当生产中的debug = False时,Django在媒体文件上显示404错误 [英] Django shows 404 error on media files when debug = False in production

查看:91
本文介绍了当生产中的debug = False时,Django在媒体文件上显示404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开django网站,并通过了部署清单并转为 debug = False 之后,django出现404错误,并且仅加载了静态文件,而没有从用户上传的媒体文件显示.但是,使用 debug = True ,所有图像和文件都可以正常工作.以下是 debug = True 的项目配置.控制台日志显示多个丢失的文件.有人可以指出我做错了什么事吗?

I'm trying to put a django website live and after going through the deployment checklist and turning debug = False django gives out a 404 error and only static files are loaded no media files uploaded from users are displayed. However with debug=True all the images and files work properly. below are the configurations of the project with debug = True. The console logs show multiple missing files.can someone point to me what i'm doing wrong?

settings.py

settings.py

urls.py

控制台错误

推荐答案

基本上,您将应用程序置于 DEBUG = False "mode"下,这意味着django将不会提供任何静态文件.但是另一方面,如果要在本地测试 DEBUG = False 对环境的影响,则可以在本地使用 python manage.py runserver --insecure 选项,该选项允许django提供静态文件.但是我必须指出,这是非常低效的,也许也不安全.

Basically you are putting the application in DEBUG=False "mode", this means that django won't serve any static files. But on the other hand, if you want to test locally how DEBUG=False affects your environment, locally you can use python manage.py runserver --insecure option which will allow django to serve static files. But I must note that this is vastly inefficient and maybe insecure too.

希望这会有所帮助.

这篇关于当生产中的debug = False时,Django在媒体文件上显示404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆