简体   繁体   English

Heroku 上的 Django - 缺少静态文件 manifest.json 文件

[英]Django on Heroku - missing staticfiles manifest.json file

I am trying to start Django on Heroku.我正在尝试在 Heroku 上启动 Django。 I looked around Stack Overflow, I tried different things, but I cannot figure it out.我环顾 Stack Overflow,尝试了不同的方法,但我无法弄清楚。 It looks similar to all the questions related to staticfiles problem on Django, unfortunately I don't know where the problem is.它看起来与Django上所有与静态文件问题相关的问题相似,不幸的是我不知道问题出在哪里。 My project runs just fine with DEBUG = True , but when I change it to False, I get following traceback:我的项目在DEBUG = True运行得很好,但是当我将其更改为 False 时,我得到以下回溯:

2020-11-09T13:13:42.801384+00:00 app[web.1]: Missing staticfiles manifest entry for 'order/css/open-iconic-bootstrap.min.css'

It happens on all of my apps that require staticfiles.它发生在我所有需要静态文件的应用程序上。 I tried to find manifest.json, but it does not exist.我试图找到 manifest.json,但它不存在。 So I think this is the issue.所以我认为这就是问题所在。

Here are my relevant settings:这是我的相关设置:

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
#more ...
]
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'

django_heroku.settings(locals())

Thanks for looking into this!感谢您查看这个!

@keome in the comments already gave you the first steps in debugging this issue so I won't repeat that here.评论中的@keome 已经为您提供了调试此问题的第一步,因此我不会在这里重复。

Notwithstanding the issues they raised (which should be looked at first), I think the key issue is that your whitenoise configuration isn't set up to generate a manifest.尽管他们提出了问题(应该首先考虑),但我认为关键问题是您的白噪声配置未设置为生成清单。 You probably want:你可能想要:

# Serve compressed and manifested static files
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

The reason your current configuration would work with DEBUG=1 is that in debug mode, django will fall back to serve static files itself (neither secure nor efficient).您当前的配置可以使用DEBUG=1是在调试模式下,django 将回退以提供静态文件本身(既不安全也不高效)。

Second, make sure that you run collectstatic with the same storage configuration as you're running the server - I cant see what settings files you have, but it seems like you've collected static without a manifesting strategy, but you're trying to serve it with a manifesting strategy (and hence django is confused by why there isn't a manifest).其次,确保您使用与运行服务器相同的存储配置运行collectstatic - 我看不到您拥有哪些设置文件,但您似乎收集了没有明显策略的静态数据,但您正在尝试使用显式策略为其提供服务(因此 django 对为什么没有清单感到困惑)。

Incidentally, whitenoise by default creates a staticfiles.json file, not a manifest.json file, and it's served as a static file.顺便说一下,whitenoise 默认创建一个staticfiles.json文件,而不是manifest.json文件,它作为一个静态文件。 So if your STATIC_URL = "/static/" then you can find the manifest at <your-domain>/static/staticfiles.json .所以如果你的STATIC_URL = "/static/"那么你可以在<your-domain>/static/staticfiles.json找到清单。

Edit - clarification编辑 - 澄清

The reason the manifest of staticfiles isn't actually called manifest.json is because that'd conflict with the usual name of the manifest.json served as part of a Progressive Web App ( spec here ), which is kind of similar (in that it can serve as an instruction to the browser of where to find certain files) but not the same. staticfiles 的清单实际上没有被称为manifest.json的原因是因为它与作为渐进式 Web 应用程序一部分的manifest.json的通常名称冲突(此处规范),这有点相似(在那个它可以作为浏览器在哪里找到某些文件的指令)但不一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django模型:ValueError:“ file_name.ext”缺少静态文件清单条目 - Django Model: ValueError: Missing staticfiles manifest entry for “file_name.ext” 在 Heroku 上找不到 Django 静态文件(带白噪声) - Django staticfiles not found on Heroku (with whitenoise) Django 不加载静态文件 ValueError(“缺少 &#39;%s&#39; 的静态文件清单条目”% clean_name) - Django doesn't load static files ValueError(“Missing staticfiles manifest entry for '%s'” % clean_name) Django:ValueError:缺少“jquery.twbsPaginationAlt.min.js”的静态文件清单条目 - Django: ValueError: Missing staticfiles manifest entry for 'jquery.twbsPaginationAlt.min.js' 将 Django 应用程序部署到 Heroku 无法加载静态文件 - Deploying Django App to Heroku Cant load Staticfiles 如何修复在heroku中找不到的django staticfiles页面? - how to fix django staticfiles page not found in heroku? ValueError:缺少“favicon.ico”的静态文件清单条目 - ValueError: Missing staticfiles manifest entry for 'favicon.ico' 在 S3 上存储静态文件,但在本地存储 staticfiles.json 清单 - Store static files on S3 but staticfiles.json manifest locally 如何调试带有白噪声、gunicorn 和 heroku 的 django 静态文件? - How to debug django staticfiles served with whitenoise, gunicorn, and heroku? 如何修复 [Errno 20] 不是目录:&#39;/app/myProjectManager/settings.py/staticfiles/staticfiles.json&#39; Django - How to fix [Errno 20] Not a directory: '/app/myProjectManager/settings.py/staticfiles/staticfiles.json' Django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM