为什么我应该只允许在调试模式下上传图像?

发布于 2025-01-20 17:40:38 字数 302 浏览 1 评论 0原文

我想添加一个字段供用户编辑他们的个人资料图片并查看了一些教程。但是,我发现的每个教程都在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不忘初心 2025-01-27 17:40:38

这是因为在生产模式下 django 停止提供静态文件。
因此静态 url 将导致找不到页面。

This is because in production mode django stop serving static files.
Thus static url will result in a page not found.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文