Wagtail 前端的文档 link
Document link on front end in Wagtail
如果我将文档上传到 Wagtail CMS,我怎样才能使它在前端可供下载?有没有具体的模板标签?
一旦您引用了文档对象,它的 .url
属性 将为您提供正确的 URL 下载:
<a href="{{ document.url }}">{{ document.title }}</a>
至于如何首先获得该引用 - 通常您会通过将它与 wagtaildocs.Document
的外键相关联来实现,其方式与本教程显示的方式大致相同 associating images with pages:
from wagtail.documents.edit_handlers import DocumentChooserPanel
class MyPage(Page):
# ...
related_document = models.ForeignKey(
'wagtaildocs.Document', blank=True, null=True,
on_delete=models.SET_NULL, related_name='+'
)
content_panels = Page.content_panels + [
# ...
DocumentChooserPanel('related_document')
]
(在这种情况下,您将在模板中将文档引用为 page.related_document
,例如 <a href="{{ page.related_document.url }}">
。)
如果我将文档上传到 Wagtail CMS,我怎样才能使它在前端可供下载?有没有具体的模板标签?
一旦您引用了文档对象,它的 .url
属性 将为您提供正确的 URL 下载:
<a href="{{ document.url }}">{{ document.title }}</a>
至于如何首先获得该引用 - 通常您会通过将它与 wagtaildocs.Document
的外键相关联来实现,其方式与本教程显示的方式大致相同 associating images with pages:
from wagtail.documents.edit_handlers import DocumentChooserPanel
class MyPage(Page):
# ...
related_document = models.ForeignKey(
'wagtaildocs.Document', blank=True, null=True,
on_delete=models.SET_NULL, related_name='+'
)
content_panels = Page.content_panels + [
# ...
DocumentChooserPanel('related_document')
]
(在这种情况下,您将在模板中将文档引用为 page.related_document
,例如 <a href="{{ page.related_document.url }}">
。)