问题
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
urls.py
console errors
回答1:
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.
Hope this helps.
来源:https://stackoverflow.com/questions/47948586/django-shows-404-error-on-media-files-when-debug-false-in-production