一旦您引用了文档对象,它的.url属性就会为您提供正确的下载 URL:
<a href="{{ document.url }}">{{ document.title }}</a>
Run Code Online (Sandbox Code Playgroud)
至于你如何首先获得该引用 - 通常你会通过将它与外键相关联来实现wagtaildocs.Document,这与教程显示的将图像与页面相关联的方式大致相同:
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')
]
Run Code Online (Sandbox Code Playgroud)
(在这种情况下,您可以将模板中的文档称为page.related_document,例如<a href="{{ page.related_document.url }}">。)
| 归档时间: |
|
| 查看次数: |
1858 次 |
| 最近记录: |