为什么我应该只允许在调试模式下上传图像?
我想添加一个字段供用户编辑他们的个人资料图片并查看了一些教程。但是,我发现的每个教程都在 urls.py 中包含某种形式的内容:
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
为什么我不能通过部署来执行此操作以及是否必须这样做?有什么办法可以让用户上传和修改他们的个人资料照片吗?
任何帮助将不胜感激。谢谢。
I want to add a field for users to edit their profile pictures and checked out a few tutorials. However, every tutorial I've found included some form of this in urls.py:
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
Why can't I do this with deployment and if it has to be like this? Is there any way for me to allow users to upload and modify their profile pictures?
Any help would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为在生产模式下 django 停止提供静态文件。
因此静态 url 将导致找不到页面。
This is because in production mode django stop serving static files.
Thus static url will result in a page not found.