debug = false 以后 无法加载静态文件 以及 admin后台管理系统样式丢失
urls.py中
from django.views.static import serve from zaobaobiao import settings urlpatterns = [ path('admin/', admin.site.urls), # 主页 path('', views.stater, name='stater'), path('upload/', views.upload, name='upload'), # 上传的文件 re_path(r'app01/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}), re_path(r'static/(?P<path>.*)', serve, {'document_root': settings.STATIC_ROOT}),
settings.py中
STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') # 关闭调试后使用 # STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ] # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' AUTH_USER_MODEL = 'app01.UserInfo' # 配置用户上传的文件存储位置 MEDIA_ROOT = os.path.join(BASE_DIR, 'app01/zbb')
最后manage 中执行 collectstatic 它会在根目录下生成static文件,里边存储的是admin的样式文件