简体   繁体   English

调试为False时找不到静态文件(404)

[英]Static Files are not found (404) when Debug is False

I want to see how my app works in production and i changed settings in my local machine, so i used below settings in settings.py 我想查看我的应用在生产中的工作方式,并更改了本地计算机上的设置,因此我在settings.py中使用了以下设置

DEBUG = False

ALLOWED_HOSTS = ['127.0.0.1', 'localhost']

STATIC_URL = '/assets/'

STATIC_ROOT = os.path.join(BASE_DIR, 'assets/')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

I used python manage.py collectstatic which copied all the files from folder static to assets 我使用python manage.py collectstatic将所有文件从static文件夹复制到assets

when i set Debug = True files served from assets with 200, one example (http://localhost:8000/assets/js/jquery-2.2.4.js) 当我将Debug = True文件设置为200时从assets提供服务时,一个示例(http://localhost:8000/assets/js/jquery-2.2.4.js)
but when i set Debug = False the static files are not found with 404 error. 但是当我设置Debug = False ,找不到404错误的静态文件。

打开调试时,服务器应该注意静态文件,无论如何,如果要继续使用debug = True,请以不安全的模式运行它,例如python manage.py runserver --insecure

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM