After django's debug is changed to false, static files do not display problem processing

Processing method:

1. Modify setting.py

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

2. Modify 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<path>.*)$', static.serve,
      {
    
    'document_root': settings.STATIC_ROOT}, name='static'),
]

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324327164&siteId=291194637