1、settings.py
STATIC_URL = '/static/'
STATIC_ROOT = 'static' # 新增
STATICFILES_DIRS = (
os.path.join(BASE_DIR, '/static/'),
)
2、urls.py
from django.contrib import admin
from django.urls import path, include, re_path # 新增
from django.conf import settings
from django.conf.urls.static import static
from django.views import static as sta # 新增
urlpatterns = [
path('admin/', admin.site.urls),
path('app/', include('app.urls')),
re_path(r'^static/(?P<path>.*)$', sta.serve, {'document_root': settings.STATIC_ROOT}, name='static') # 新增
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
ps:导入模块冲突时,可以重命名