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時候會出現不移動的情況