1.官方说明如下
按照上面信息配置时候会出现
(staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
估计是linux和windows的原因导致
这里从网上找到解决办法:
setting.py文件配置如下
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = FalseALLOWED_HOSTS = ['*', ]
STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, '/static/')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "/static/"),
]STATIC_ROOT = 'static'
url.py文件
from django.contrib import admin
from django.urls import path
from django.views import static ##新增
from django.conf import settings ##新增
from django.conf.urls import url ##新增urlpatterns = [
path('admin/', admin.site.urls),
url(r'^static/(?P<path>.*)$', static.serve,
{'document_root': settings.STATIC_ROOT}, name='static'),
]
即可解决404加载不了的问题。
官方的静态文件迁移需要用
python manage.py collectstatic
用python3时候会出现不移动的情况