/“缺少的静态文件清单”条目中的ValueError [英] ValueError at / Missing staticfiles manifest entry for ''

查看:100
本文介绍了/“缺少的静态文件清单”条目中的ValueError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Django 1.9.7迁移到Django 1.11.5。我有三个不同的django应用程序,它们在软件包和设置方面几乎相同。我已经将所有三个应用程序都部署到了Web服务器上,并且两个应用程序都正常运行,但是第三个应用程序让我头疼-我一直都遇到此错误:

I'm trying to migrate from Django 1.9.7 to Django 1.11.5. I have three different django apps, and they are pretty much the same regarding packages and settings. I have deployed all three of them to a web server and two apps are working without any problems, but third one gives me headache - i get this error all the time:

ValueError at / Missing staticfiles manifest entry for ''

的静态文件清单条目 settings.py 中最相关的设置:

Here are the most relevant settings from settings.py:

# -*- coding: utf-8 -*-
from settings import * 

SECRET_KEY = '***'

SITE_ID = 3

ALLOWED_HOSTS = [
    'localhost', 
    '127.0.0.1',
    '.example.com',
    '.example.com.',

    ]

INSTALLED_APPS += (
    'storages',
    'example',
    'example2',
    'el_pagination',
    'debug_toolbar',
)

ROOT_URLCONF = 'example.urls'

WSGI_APPLICATION = 'example.wsgi.application'

DEFAULT_FROM_EMAIL = 'web@example.com'

MANAGERS = ADMINS

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
        'DEFAULT_MIDDLEWARE_ALIAS': 'default',
        'DEFAULT_MIDDLEWARE_SECONDS': '300',
        'DEFAULT_MIDDLEWARE_KEY_PREFIX': '',
    }
}

PASSWORD_HASHERS = (
    'django.contrib.auth.hashers.SHA1PasswordHasher',
)

#AWS_HEADERS = {  # see http://developer.yahoo.com/performance/rules.html#expires
#       'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
#        'Cache-Control': 'max-age=94608000',
#S    }

# AMAZON S3 & CLOUDFRONT SERVING MEDIA FILES
AWS_S3_HOST = 's3.eu-central-1.amazonaws.com'
AWS_STORAGE_BUCKET_NAME = '***'
AWS_CLOUDFRONT_DOMAIN = '***.cloudfront.net'
AWS_ACCESS_KEY_ID = "***"
AWS_SECRET_ACCESS_KEY = "***"
MEDIAFILES_LOCATION = 'example/media'
MEDIA_ROOT = '/%s/' % MEDIAFILES_LOCATION
MEDIA_URL = '//%s/%s/' % (AWS_CLOUDFRONT_DOMAIN, MEDIAFILES_LOCATION)
DEFAULT_FILE_STORAGE = 'example.custom_storages.MediaStorage'

# WHITENOISE SERVING STATIC FILES
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, '***/static/example') 
STATIC_URL = '/static/'

我不知道为什么会收到此错误,因为与其他两个应用相比,我在部署时没有做任何不同定期工作。设置几乎一样!我还尝试清空.css文件,以免出现CSS文件指向不存在但无济于事的文件的可能性。我已经更新了我的网站使用的所有软件包。
此应用程序在Django 1.9.7下正常工作,但我无法使其在1.11.5下工作。

I don't know why i'm getting this error because i did nothing different (while deploying) comparing to the other two apps which are working regularly. Settings are almost the same! I've also tried to empty .css files so i could throw away possibility that css files are somewhere pointing to files that doesn't exist, but it didn't help. I've updated all of the packages that my websites are using. This app is working normally under Django 1.9.7, but i can't make it to work under 1.11.5.

编辑-如何我能解决这个问题吗?

由于@evansd的回答,我设法找到了问题!在我的一个模板中,我有这段代码将整个事情搞砸了:

Thanks to @evansd's answer i've managed to find the problem! In one of my templates i've had this code which messed the whole thing up:

{% for num in numbers  %}
<li>
   <img src="{% static ''%}img/header/{{num}}.jpg" alt="image {{num}}"/>
</li>
{% endfor %}

我将其更改为:

{% for num in numbers  %}
<li>
   <img src="{% static 'img/header/'|addstr:num|addstr:'.jpg' %}" alt="image {{num}}">
</li>
{% endfor %}

在此修复之后,一切正常!对于自定义的addstr模板标记,请参见此答案。 / p>

After this fix everything works well! For custom addstr template tag look this answer.

推荐答案

问题是,模板中的某个位置所引用的静态文件不存在。具体来说,您将一个空字符串传递给 static 。也许您有一行像 {%static some_variable%} 这样的行,其中 some_variable 是未定义的?

The problem is that somewhere in your templates you're referencing a static file that doesn't exist. Specifically, your passing an empty string to static. Perhaps you have a line like {% static some_variable %} where some_variable is undefined?

在Django 1.11中,行为已更改,因此错误会丢失文件。请参阅:
https://docs.djangoproject.com/zh-CN/1.11/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict

In Django 1.11 the behaviour changed so that errors are thrown on missing files. See: https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict

如果您修复此参考文献,则一切正常。

If you fix this reference then everything should work.

这篇关于/“缺少的静态文件清单”条目中的ValueError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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