1.设置settings.py
DEBUG = False
ALLOWED_HOSTS = ["*"]
...
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
2.修改项目的urls.py
from django.contrib import admin
from django.urls import path
from django.urls import include, path,re_path
from django.views.static import serve
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
...,
re_path(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),
]
3.执行django转移静态文件命令
python manage.py collectstatic
4.问题解决