I am trying to embed a pdf in a Django template. I am using the same way we are embedding an image in django. It`s seems that the file cannot be found. Is there a different way to display it?
Many Thanks
views.py
class BillDetailView(generic.DetailView):
model = Bill
template_name = 'accounting/bills/bill_detail.html'
models.py
class BillFile(models.Model):
bill = models.ForeignKey(Bill,on_delete=models.CASCADE, blank=True, null=True, unique=False)
bill_file = models.FileField(upload_to='media/bill_files/', default='bill_files/default_id.jpg', blank =True)
bill_detail.html
<div class="card-block">
{% if billfile.bill_file %}
<div class="top-right"></div>
<!-- Option 1 -->
<embed src="{{ billfile.bill_file.url }}" width = "200" height = "240" style =" margin-left: auto; margin-right: auto; display: block;">Click me</a>
<!-- Option 2 -->
<iframe src="{{ billfile.bill_file.url }}" style="width: 100%;height: 100%;border: none;"></iframe>
<!-- Option 3 -->
<a href="{% static '{{ billfile.bill_file }}' %}">Click me</a>
{% else %}
<h3>There is no file to display</h3>
{% endif %}
</div>