Django不会加载静态文件ValueError(“缺少'%s'的静态文件清单条目"“%clean_name) [英] Django doesn't load static files ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)

查看:92
本文介绍了Django不会加载静态文件ValueError(“缺少'%s'的静态文件清单条目"“%clean_name)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是我在Django中的第一个应用程序,我正在尝试准备将Django(2.0)应用程序用于生产,但是我无法使用

is my first app in Django and I am trying to prepare my Django (2.0) application for production, but I am unable to make the static files load properly using WhiteNoise

我一直在日志中一直遇到下一个错误

I keep having all the time the next error in my log

ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
ValueError: Missing staticfiles manifest entry for 'css/inicio.css'
[02/Jun/2018 14:40:37] ERROR [django.server:124] "GET /participation/prueba HTTP/1.1" 500 27

我有以下设置.py

...
DEBUG=False
DJANGO_APPS = ['django.contrib.admin',
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.sessions',
                'django.contrib.messages',
                #Delete for development whitenoise.runserver_nostatic
                'whitenoise.runserver_nostatic',
                'django.contrib.staticfiles',
                'django.contrib.sites'
               ]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
...
STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')

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

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

我所有的静态文件都在一个文件夹中,在根目录下称为static,当我运行manage.py collectstatic时,我将生成所有静态文件staticfiles目录,但是仍然不知何故我无法使其运行.

I have all my static files in a folder call static at root level, when I run manage.py collectstatic I get generate all the static files in the staticfiles dir, but somehow still I don't manage to make it run.

我试图找出问题所在,并且正在使用以下模板

I try to isolate the problem and I am using the following template

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    {% load static %}
    <link rel="stylesheet" href="{% static "css/inicio.css" %}">
</head>
<body>


{% for categoria in categoria_list %}
    <p>
        {{ categoria.titulo }}
    </p>
{% endfor %}


</body>
</html>

我已经尝试将href的路径更改为

I have try already to change the path of href to

{% static "/css/inicio.css" %}
{% static "static/css/inicio.css" %}

但没有一个可以加载

我也尝试过有无'whitenoise.runserver_nostatic'在Django Apps中加载后,结果一直保持不变.

Also I tried with and without 'whitenoise.runserver_nostatic' loaded in Django Apps and I keep having the same results.

有人知道我在做什么错吗?

Anyone knows what i am doing wrong ?

谢谢.

推荐答案

尝试删除此行,

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

来源: https://stackoverflow.com/a/32347324/2596187

这篇关于Django不会加载静态文件ValueError(“缺少'%s'的静态文件清单条目"“%clean_name)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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