我是 Django 初学者。当我编写文件上传代码时,我不明白这段代码
if settings.DEBUG:
urlpatterns+=static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
为什么我们必须编写if settings.DEBUG:
?
最佳答案
这两行allow the development server to serve user-uploaded files在 MEDIA_ROOT
目录中。
您不应该在生产中执行此操作,因此添加了 if settings.DEBUG
检查。在生产中,您应该配置服务器(例如 Nginx 或 Apache)来提供媒体和静态文件,或者从 CDN 提供它们。
关于python - Django 'if settings.DEBUG:' 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45464400/