1、处于非Debug模式
settings.py文件
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
2、设置ROOT
官方设置文档
https://docs.djangoproject.com/en/2.2/howto/static-files/
在本地路径创建 static文件夹
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# # 自加静态目录配置
# STATICFILES_DIRS = [
# os.path.join(BASE_DIR, "static"),
# ]
3、URL的设置
添加 STATIC_ROOT STATIC_URL到路由中
from django.contrib import admin
from django.urls import path, re_path
from django.conf.urls import include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'bookstore/', include('bookstore.urls'))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
4、收集静态文件到本地
'将系统css文件拷贝至 本地项目中'
python manage.py collectstatic
重启项目
http://127.0.0.1:8000/admin/