修复调试模式下静态文件响应500的问题

This commit is contained in:
zmister 2022-05-21 21:26:46 +08:00
parent 32a647f44a
commit d54976c646
2 changed files with 10 additions and 2 deletions

View File

@ -187,6 +187,7 @@ LOCALE_PATHS = (
STATIC_URL = '/static/'
if DEBUG:
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]
STATICFILES_DIR = os.path.join(BASE_DIR, 'static')
else:
STATIC_ROOT = os.path.join(BASE_DIR,'static')

View File

@ -32,7 +32,7 @@ urlpatterns = [
path('admin/',include('app_admin.urls'),), # admin应用
path('api/',include('app_api.urls')), # 用户 Token API 接口
path('api_app/',include('app_api.urls_app')), # RESTFUL API 接口
re_path('^static/(?P<path>.*)$',serve,{'document_root':settings.STATIC_ROOT}),# 静态文件
# re_path('^static/(?P<path>.*)$',serve,{'document_root':settings.STATIC_ROOT}),# 静态文件
re_path('^media/(?P<path>.*)$',serve,{'document_root':settings.MEDIA_ROOT}),# 媒体文件
path('sitemap.xml', views.index, {'sitemaps': sitemaps,'template_name':'sitemap/sitemap-index.xml'},name='sitemap',), # 站点地图索引
path('sitemap-<section>.xml', views.sitemap, {'sitemaps': sitemaps,'template_name':'sitemap/sitemap.xml'},
@ -40,8 +40,15 @@ urlpatterns = [
]
if settings.DEBUG:
urlpatterns.append(
re_path('^static/(?P<path>.*)$',serve,{'document_root':settings.STATICFILES_DIR}),# 静态文件
)
try:
import debug_toolbar
urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))
except ImportError:
pass
pass
else:
urlpatterns.append(
re_path('^static/(?P<path>.*)$',serve,{'document_root':settings.STATIC_ROOT}),# 静态文件
)