1. 首先修改App 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<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'), ]