python config_error ai_generated true

Django配置错误:你正在使用staticfiles应用而没有设置STATIC_ROOT为文件系统路径。

django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

ID: python/django-static-file-not-found

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-07-01首次发现

版本兼容性

版本状态引入弃用备注
3.x active

根因分析

在使用collectstatic或生产环境中提供静态文件时,STATIC_ROOT未配置。

English

STATIC_ROOT is not configured when using collectstatic or serving static files in production.

generic

解决方案

  1. 95% 成功率 Set STATIC_ROOT in settings.py
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  2. 90% 成功率 Run collectstatic after setting
    python manage.py collectstatic

无效尝试

常见但无效的做法:

  1. Setting STATIC_ROOT to a non-existent path 80% 失败

    Directory must exist or be created.

  2. Ignoring the setting and using STATICFILES_DIRS only 90% 失败

    collectstatic requires STATIC_ROOT.