django的debug改为false后静态文件不显示问题处理

处理办法:

1.修改setting.py

STATIC_URL = '/static/'
STATIC_ROOT = 'static' ## 新增行
STATICFILES_DIRS = [
  os.path.join(BASE_DIR, '/static/'), ##修改地方
]

2.修改urls.py

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

参考:
https://blog.csdn.net/weixin_43670190/article/details/113818571
https://www.cnblogs.com/ievjai/p/9926187.html

你可能感兴趣的:(django,python,debug,static)