Django set DEBUG = False solve the static files could not be loaded

python3.6+django2.2

1. Modify the project setting.py

STATIC_URL = '/static/'
STATIC_ROOT = 'static' ## 新增行
STATICFILES_DIRS = [
    os.path.join(BASE_DIR,'/static/'),
   # os.path.join(BASE_DIR,'log_analysis/log_analysis_static/'),
]

2. Modify urls.py:

from django.conf import settings
from django.conf.urls import url, include
    
# path('', include('user.urls')),(增加以下url)
    url(r'^static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
]

 Restart the server, to solve the problem

 

Guess you like

Origin www.cnblogs.com/linwenbin/p/11607857.html