解决Django设置debug=False时静态文件获取不到的问题
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 .*)$', sta.serve, {'document_root': settings.STATIC_ROOT}, name='static') # 新增
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/m0_62202010/article/details/135649223