[英]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
找到清单。
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.