[英]How can I dynamically serve files and then make them downloadable in Django?
[英]How to make the document files downloadable from wagtail?
我已將 pdf 上傳到我的 wagtail 頁面,但我無法弄清楚如何讓它們實際上可以從網頁本身下載。 這是我的models.py 文件的代碼。
我需要什么 html 代碼來制作這些?
class ArchitectPage(Page):
pdf_files = models.ForeignKey(
'wagtaildocs.Document',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
search_fields = Page.search_fields + [
] # these are if adding a search to the website
# content tab panels
content_panels = Page.content_panels + [
MultiFieldPanel(
[InlinePanel('architect_pdf', max_num=20, min_num=0, label="architect pdf")],
heading="architect pdf"
),
]
# what to call the panels on wagtail
edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'),
ObjectList(Page.promote_panels, heading='SEO'),
ObjectList(Page.settings_panels, heading='Settings', classname='settings'),
# classname settings adds the cog
])
class ArchitectDownloads(Orderable):
page = ParentalKey(ArchitectPage, on_delete=models.CASCADE, related_name='architect_pdf')
architect_pdf = models.ForeignKey(
'wagtaildocs.Document',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
panels = [
DocumentChooserPanel('architect_pdf'),
]
<ul>
{% for download in page.architect_pdf.all %} {# loop over the ArchitectDownload objects #}
{% with doc=download.architect_pdf %} {# retrieve the Document object for each one #}
<li><a href="{{ doc.url }}">{{ doc.title }}</a></li>
{% endwith %}
{% endfor %}
</ul>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.