Django ValueError:缺少静态文件清单条目,但清单似乎显示了该条目 [英] Django ValueError: Missing staticfiles manifest entry, but the manifest appears to show the entry

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

问题描述

在部署到Heroku的Django 1.11应用程序上.加载根URL /时(我猜想Django在homepage.html模板中进入{% static 'angular/angular.min.js' %}时),出现以下错误:

On a Django 1.11 app deployed to Heroku. When loading the root URL / (and I presume when Django gets to {% static 'angular/angular.min.js' %} in the homepage.html template) I get the following error:

ValueError: Missing staticfiles manifest entry for 'angular/angular.min.js'
  File "django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "homepage/views.py", line 87, in homepage
    "latest_python3": Version.objects.filter(supports_python3=True).select_related("package").distinct().order_by("-created")[0:5]
  File "django/shortcuts.py", line 30, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "django/template/loader.py", line 68, in render_to_string
    return template.render(context, request)
  File "django/template/backends/django.py", line 66, in render
    return self.template.render(context)
  File "django/template/base.py", line 207, in render
    return self._render(context)
  File "newrelic/api/function_trace.py", line 60, in dynamic_wrapper
    return wrapped(*args, **kwargs)
  File "django/template/base.py", line 199, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 990, in render
    bit = node.render_annotated(context)
  File "django/template/base.py", line 957, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 177, in render
    return compiled_parent._render(context)
  File "newrelic/api/function_trace.py", line 60, in dynamic_wrapper
    return wrapped(*args, **kwargs)
  File "django/template/base.py", line 199, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 990, in render
    bit = node.render_annotated(context)
  File "django/template/base.py", line 957, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 411, in render
    return strip_spaces_between_tags(self.nodelist.render(context).strip())
  File "django/template/base.py", line 990, in render
    bit = node.render_annotated(context)
  File "django/template/base.py", line 957, in render_annotated
    return self.render(context)
  File "newrelic/hooks/framework_django.py", line 765, in wrapper
    return wrapped(*args, **kwargs)
  File "django/template/loader_tags.py", line 72, in render
    result = block.nodelist.render(context)
  File "django/template/base.py", line 990, in render
    bit = node.render_annotated(context)
  File "django/template/base.py", line 957, in render_annotated
    return self.render(context)
  File "django/templatetags/static.py", line 105, in render
    url = self.url(context)
  File "django/templatetags/static.py", line 102, in url
    return self.handle_simple(path)
  File "django/templatetags/static.py", line 117, in handle_simple
    return staticfiles_storage.url(path)
  File "django/contrib/staticfiles/storage.py", line 162, in url
    return self._url(self.stored_name, name, force)
  File "django/contrib/staticfiles/storage.py", line 141, in _url
    hashed_name = hashed_name_func(*args)
  File "django/contrib/staticfiles/storage.py", line 432, in stored_name
    raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)

清单中有什么?

我对 Django文档是清单是一个名为staticfiles.json的文件.该文件似乎包含正确的条目(出于格式化的原因,我已删除了所有不相关的条目):

What's in the manifest?

My understanding of the Django docs is that the manifest is a file called staticfiles.json. That file appears to contain the correct entry (For formatting reasons I have removed all unrelated entries):

$ heroku run cat ./staticfiles/staticfiles.json
Running cat ./staticfiles/staticfiles.json
{"paths": {"angular/angular.min.js": "angular/angular.min.df1c56732ca5.js", "angular/controllers.js": "angular/controllers.af8e9f9a2645.js"}, "version": "1.0"}

相关设置:

我遵循了 Heroku关于使用Django服务静态文件的说明:

# in requirements.txt
whitenoise

# in settings/base.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
STATIC_URL = "/static/"
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"),]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    # ...others here too
]

django_heroku.settings(locals())

(更新:STATICFILES_STORAGE)

基于以下建议之一,我删除了STATICFILES_STORAGE的值. django-heroku将STATICFILES_STORAGE的值设置为whitenoise.storage.CompressedManifestStaticFilesStorage.我通过在我的settings.py文件的末尾添加del STATICFILES_STORAGE来删除了此内容.然后,Django将值重置为默认的django.contrib.staticfiles.storage.StaticFilesStorage.结果是所有静态文件都在浏览器中出现404或MIME类型错误.

(UPDATE: STATICFILES_STORAGE)

Based on one of the suggestions below, I removed the value of STATICFILES_STORAGE. django-heroku sets the value of STATICFILES_STORAGE to whitenoise.storage.CompressedManifestStaticFilesStorage. I removed this by adding del STATICFILES_STORAGE to the end of my settings.py file. Django then reset the value to the default django.contrib.staticfiles.storage.StaticFilesStorage. The result is that all of the static files either 404 or get MIME type errors in the browser.

推荐答案

您是否手动创建了staticfiles目录,然后在部署前运行django-admin collectstatic?

Did you manually create the staticfiles directory, then run django-admin collectstatic before deployment?

这是文档.

这篇关于Django ValueError:缺少静态文件清单条目,但清单似乎显示了该条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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