admin管理员组文章数量:1125579
In wagtail I have uploaded a document to admin/Documents How in python code can I generate a link to download the document I tried generating a link such as
/documents/<document_id>/<document.pdf>
but I am getting access denied errors in Wagtail template
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>5QNKMKYX4M4TW71A</RequestId>
<HostId>WFI1UWghb12TK+/PKPWIERNfCUTPX3qSGFPMHmb/bJnv8kcqQ5M3ctG0MrjZeum4rzIJbtyHIcU=</HostId>
</Error>
In wagtail I have uploaded a document to admin/Documents How in python code can I generate a link to download the document I tried generating a link such as
/documents/<document_id>/<document.pdf>
but I am getting access denied errors in Wagtail template
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>5QNKMKYX4M4TW71A</RequestId>
<HostId>WFI1UWghb12TK+/PKPWIERNfCUTPX3qSGFPMHmb/bJnv8kcqQ5M3ctG0MrjZeum4rzIJbtyHIcU=</HostId>
</Error>
Share
Improve this question
asked 2 days ago
DavidUDavidU
897 bronze badges
2 Answers
Reset to default 0If a file is uploaded to a field on your model, for example
from wagtail.admin.panels import FieldPanel
from wagtail.documents import get_document_model
from wagtail.models import Page
class HomePage(Page):
custom_document = models.ForeignKey(
get_document_model(),
null=True
blank=True
on_delete=models.SET_NULL
related_name='+'
)
content_panels = Page.content_panels + [
FieldPanel('custom_document'),
]
In this case you can access url: page.custom_document.url
If you want to know the path to the document directly, that depends on your settings. See Wagtail documentation here for user-uploaded content and also here on storing and serving files.
I my case I added this to my url patterns:
urlpatterns.append(path('wagtail_documents/', include(wagtaildocs_urls)))
So I know I store my documents here:
wagtail_documents/id/filename.doc
The error you show indicates S3 is requiring an authorization token to serve your file. This is exactly as it should be. If you allow documents to be "public-read" in S3, then there is backdoor access that renders the document privacy options useless.
Do you want all documents to download? or do you want some, such as PDFs, to display in the browser? If you want all to download, I would start by setting WAGTAILDOCS_INLINE_CONTENT_TYPES to an empty list. That may only work for references within rich text. If so, you may need to set the WAGTAILDOCS_SERVE_METHOD to "serve" and override the document serve method to set the content disposition header to attachment.
本文标签: Wagtail download link for documentStack Overflow
版权声明:本文标题:Wagtail download link for document - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736623192a1945618.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论