Django settings.py设置 DEBUG=False后静态文件无法加载解决

解决办法:

settings.py 文件

DEBUG = False
STATIC_ROOT = os.path.join(BASE_DIR,'static')   #新增

urls.py文件(项目的)

from django.views import static     #新增
from django.conf import settings   #新增
from django.conf.urls import url    #新增

urlpatterns = [
    url(r'^static/(?P<path>.*)$', static.serve,{'document_root': settings.STATIC_ROOT}, name='static'),   #新增
]

 

搞定!!!!

posted @ 2021-08-25 16:36  语~默  阅读(93)  评论(0编辑  收藏  举报