【问题标题】:Django FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\ivan\\Desktop\\Python\\static'Django FileNotFoundError: [WinError 3] 系统找不到指定的路径:'C:\\Users\\ivan\\Desktop\\Python\\static'
【发布时间】:2021-05-04 09:12:14
【问题描述】:

我正在尝试安装 django 调试工具栏来跟踪对数据库的 ORM 查询。 遇到这个错误

WARNINGS:
?: (debug_toolbar.staticfiles.W001) debug_toolbar requires the STATICFILES_DIRS directories to exist.
        HINT: Running manage.py collectstatic may help uncover the issue. 

决定运行 python manage.py collectstatic 报错 这是设置文件。

settings.py



INSTALLED_APPS = [
    #...
    'django.contrib.staticfiles',
    #..
    'debug_toolbar',
]

MIDDLEWARE = [
    #...
    'debug_toolbar.middleware.DebugToolbarMiddleware', 
]

# ...

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': str(os.path.join(BASE_DIR, "db.sqlite3")),
    }
}


# ....

STATIC_URL='/static/'
STATICFILES_DIRS =[
    os.path.join(BASE_DIR,'static').replace("\\", "/"),
]

【问题讨论】:

  • 我在STATICFILES_DIRS 中不需要替换方法,只需使用os.path.join(BASE_DIR,'static')
  • 我之前没用过。反正也没用
  • DEBUG 是否等于False 中的settings.py?如果是,并且您正在使用 runserver 运行 django,则无需执行 collectstatic,这是用于部署的。你最好也在你的settings.py 中创建一个STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

标签: python django collectstatic


【解决方案1】:

我找到了。在项目的根目录中,创建一个名为static_files 的新目录。现在该目录存在应该没问题,而且似乎需要它,因为 debug_toolbar 会查询该文件夹中的文件,出于某种原因,没有先检查该文件夹是否存在。

【讨论】:

    猜你喜欢
    • 2018-12-03
    • 2020-01-29
    • 2022-01-23
    • 2021-10-13
    • 2021-08-20
    • 2022-12-11
    • 2020-06-03
    • 2023-01-25
    • 2022-11-17
    相关资源
    最近更新 更多