0
Nun, ich bin neu auf diesem. Ich möchte wissen, ob ich eine PDF-Datei in meinem Django-Vorlage einbetten Tag angezeigt werden können wie:PDF-Vorschau mit Embed-Tag mit Django
<embed src="/file/to/pdf/some_pdf.pdf" />
Ich habe versucht:
<embed src="{{form.file_path.value}}" width="500" height="525" />
Wo {{form.file_path.value}} ist mein Verzeichnis oder Name der PDF-Datei in der Datenbank gespeichert.
Dies ist die forms.py Datei:
fields = [
'title',
'publication_date',
'file_path',
'size',
'authors',
'editorial',
]
labels = {
'title': 'Title',
'publication_date': 'Publication Date',
'file_path': 'File preview',
'size': 'Size',
'authors': 'Authors',
'editorial': 'Editorial',
}
widgets = {
'title':forms.TextInput(attrs={'class':'form-control'}),
'publication_date':forms.TextInput(attrs={'class':'form-control'}),
'file_path':forms.TextInput(attrs={'class':'form-control'}),
'size':forms.TextInput(attrs={'class':'form-control'}),
'authors': forms.CheckboxSelectMultiple(),
'editorial': forms.Select(attrs={'class':'form-control'}),
}
Und das ist die views.py Datei:
class BookList(ListView):
model = Book
template_name = 'book/book_list.html'
context_object_name = 'book'
queryset = Book.objects.prefetch_related('authors')
paginate_by = 10
def get_context_data(self, **kwargs):
context = super(BookList,self).get_context_data(**kwargs)
book_list =Book.objects.all()
paginator = Paginator(book_list,self.paginate_by)
page = self.request.GET.get('page')
try:
book_list = paginator.page(page)
except PageNotAnInteger:
file_book = paginator.page(1)
except EmptyPage:
book_list = paginator.page(paginator.num_pages)
context['book_list'] = book_list
return context