Django findstatic:找不到匹配的文件 [英] Django findstatic : No matching file found

查看:221
本文介绍了Django findstatic:找不到匹配的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间,我尝试在Django中使用 collectstatic来提供我的静态文件,但失败了。现在,我终于试图使我的静态文件在我的开发环境中正确运行。我不知道出了什么问题。

A while ago, I attempted to use "collectstatic" in Django to serve my static files and failed miserably. Now I am finally trying to get my static files serving correctly in my development environment. I can't figure out what has gone wrong.

当我运行 python manage.py findstatic images / add.png

控制台返回:

base path: C:\Projects\AlmondKing\AlmondKing
static files dirs: C:\Projects\AlmondKing\AlmondKing\static
No matching file found for 'images/add.png'.

目录路径正确,但是仍然找不到我的文件。我尝试了许多不同的设置配置,但均无济于事。谁能发现我的问题?以下是我认为所有相关的设置:

The directory paths are correct, but it still can't locate my files. I've tried a number of different settings configurations to no avail. Can anyone spot my problem? Here are what I think are all the relevant settings:

BASE_DIR = os.path.abspath(os.path.dirname(__file__))

DEBUG = True

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'AlmondKing.InventoryLogs',
    'AlmondKing.FinancialLogs',
    'AlmondKing.AKGenius',
)

STATIC_URL = '/static/'
STATIC_FILES_DIRS = (
    os.path.join((BASE_DIR), "static")
)

print("base path:", BASE_DIR)
print("static files dirs:", STATIC_FILES_DIRS)

编辑:我发现 findstatic --verbosity 2命令,唯一要搜索的目录是: C:\Users\Adam\Envs\AlmondKing\lib\site-packages\ django\contrib\admin\static

I found the findstatic --verbosity 2 command and the only directory being searched is: C:\Users\Adam\Envs\AlmondKing\lib\site-packages\django\contrib\admin\static

显然它是onl在我的虚拟环境中,而不是我的项目目录中查找。这是正常的Django行为吗?

Apparently it is only looking in my virtual environment, instead of my project directory. Is this normal Django behavior?

推荐答案

设置为 STATICFILES_DIRS ,而不是 STATIC_FILES_DIRS

在设置中您还缺少逗号。没有逗号,它将被视为字符串而不是元组。

You are also missing a comma in the setting. Without the comma it is treated as a string not a tuple.

应为:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

这篇关于Django findstatic:找不到匹配的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆