DEBUG = False
ALLOWED_HOSTS = ["*"]

...


STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
django设置debug=false时静态文件丢失

2.修改项目的urls.py

django设置debug=false时静态文件丢失
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}),
]
django设置debug=false时静态文件丢失

3.执行django转移静态文件命令

python manage.py collectstatic

4.问题解决

 

上一篇:计算机网络实验之验证性实验


下一篇:【每日一题】2022年1月4日-22. 括号生成