wagtail {{document.url}}正在生产中返回404的用户使用文件
我继承了Wagtail CMS项目,但无法解决与文档上传有关的问题。
通过CMS上传文件后,它到达文档目录/var/www/example.com/wagtail/media/media/documents/test_pdf.pdf.pdf
将映射到/usr/src /app/media/documents/test_pdf.pdf
docker容器内的目录。
在前端(以及wagtail仪表板)中,document.url解析为https://example.com/documents/9/test_pdf.pdf/
返回404。显然,型号编号段从上面的文件路径中丢失,但是我在论坛上阅读在论坛上
在Wagtail中,始终通过Django视图(wagtail.wagtaildocs.views.serve.serve.serve)提供文档,以便我们可以在文档下载
上执行其他处理
因此也许这本身不是问题。
有几行,wile  look 正确:
urlpatterns = [
url(r'^django-admin/', admin.site.urls),
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'^search/$', search_views.search, name='search'),
url(r'^sitemap\.xml$', sitemap),
url(r'', include(wagtail_urls)),
# url(r'^pages/', include(wagtail_urls)),
]
if settings.DEBUG:
...
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
和base.py.py.py
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/
so,我的直觉是:
urls.py
文件中 错误地存储在单个文件夹中,而不是通过模型存储在子目录中中的子目录中的上传。与此“虚拟”目录的路由被损坏,因此它在“检查权限”阶段破裂(但是我无法弄清楚路由的工作方式在django中)并返回404
web服务器的配置不正确,因此虽然“虚拟” URL很好,但实际上是损坏的文件URL,这会导致404(我的nginx包含A/媒体/位置,而不是A/Documents/location/location/tocuments/location,否则我会预期)
完全是其他事情(我的下一步是将副本拉到我自己的计算机上,看看问题是否仍然发生)
,我感谢这里没有太多事情要做,但我希望有人可以给我一些关于我应该检查的还有什么,因为我一天中的大部分时间都一直在与之抗衡。
我的背景是与Ruby在Rails上的背景,因此,与该框架一样,我觉得在幕后发生了很多“魔术”,这使得弄清楚发生了什么事,这很棘手。
谢谢!
I've inherited a Wagtail CMS project but have been unable to solve an issue relating to document uploads.
Having uploaded a file through the CMS, it arrives in the documents directory /var/www/example.com/wagtail/media/documents/test_pdf.pdf
which maps to the /usr/src/app/media/documents/test_pdf.pdf
directory inside the docker container.
In the front end (and within the Wagtail dashboard) the document.url resolves to https://example.com/documents/9/test_pdf.pdf/
which returns a 404. Obviously the model number segment is missing from the file path above, but I read on a forum that
In Wagtail, documents are always served through a Django view (wagtail.wagtaildocs.views.serve.serve) so that we can perform additional processing on document downloads
so perhaps this, in itself, is not an issue.
There are a couple of lines in urls.py
file which look correct:
urlpatterns = [
url(r'^django-admin/', admin.site.urls),
url(r'^admin/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'^search/
and in base.py
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/
So, my hunch is one of either:
-
Uploads being stored incorrectly, in a single folder rather than in subdirectories by model
-
The routing to this “virtual” directory is broken, so it’s breaking at the "check permissions" stage (but I couldn't figure out how routing works in Django) and returning the 404
-
The web server is incorrectly configured, so whilst the “virtual” URL is fine it’s actually the file URL which is broken and THIS causes the 404 (my nginx contains a /media/ location but not a /documents/ location, as I would have expected)
-
Something else entirely (my next step is to pull a copy down to my own machine and see if the issue still occurs)
I appreciate there isn't much to go on here but I'm hoping that someone might be able to give me some pointers as to what else I should check, as I've been banging my head against this for most of the day.
My background is with Ruby on Rails so, as with that framework, I've a feeling that there is a lot of "magic" happening behind-the-scenes that is making it very tricky to figure out what's going on.
Thanks!
, search_views.search, name='search'),
url(r'^sitemap\.xml
and in base.py
So, my hunch is one of either:
-
Uploads being stored incorrectly, in a single folder rather than in subdirectories by model
-
The routing to this “virtual” directory is broken, so it’s breaking at the "check permissions" stage (but I couldn't figure out how routing works in Django) and returning the 404
-
The web server is incorrectly configured, so whilst the “virtual” URL is fine it’s actually the file URL which is broken and THIS causes the 404 (my nginx contains a /media/ location but not a /documents/ location, as I would have expected)
-
Something else entirely (my next step is to pull a copy down to my own machine and see if the issue still occurs)
I appreciate there isn't much to go on here but I'm hoping that someone might be able to give me some pointers as to what else I should check, as I've been banging my head against this for most of the day.
My background is with Ruby on Rails so, as with that framework, I've a feeling that there is a lot of "magic" happening behind-the-scenes that is making it very tricky to figure out what's going on.
Thanks!
, sitemap),
url(r'', include(wagtail_urls)),
# url(r'^pages/', include(wagtail_urls)),
]
if settings.DEBUG:
...
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
and in base.py
So, my hunch is one of either:
Uploads being stored incorrectly, in a single folder rather than in subdirectories by model
The routing to this “virtual” directory is broken, so it’s breaking at the "check permissions" stage (but I couldn't figure out how routing works in Django) and returning the 404
The web server is incorrectly configured, so whilst the “virtual” URL is fine it’s actually the file URL which is broken and THIS causes the 404 (my nginx contains a /media/ location but not a /documents/ location, as I would have expected)
Something else entirely (my next step is to pull a copy down to my own machine and see if the issue still occurs)
I appreciate there isn't much to go on here but I'm hoping that someone might be able to give me some pointers as to what else I should check, as I've been banging my head against this for most of the day.
My background is with Ruby on Rails so, as with that framework, I've a feeling that there is a lot of "magic" happening behind-the-scenes that is making it very tricky to figure out what's going on.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在开发时看到文档,因为
static
文件媒体
应在服务器级别上处理。例如,如果您使用的是GCP,则需要更新app.yaml
,并添加MEDIA/
与static/
相同的方式You are able to see documents while developing because of
Like
static
filesmedia
files should be handled on server level. For example, if you are using GCP you need to update yourapp.yaml
and addmedia/
the same way asstatic/