首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在heroku服务中推送css

无法在heroku服务中推送css
EN

Stack Overflow用户
提问于 2021-10-31 14:26:33
回答 3查看 340关注 0票数 0

我在做什么?

  • 我试图在heroku服务器上部署django web应用程序。

问题

  • 我无法使用git push heroku main在heroku服务器上推送css文件。
  • 当我从静态文件夹中删除css文件时,一切都进行得很顺利。

更多

  • 我也安装了whitenoise .
代码语言:javascript
复制
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: -----> $ python manage.py collectstatic --noinput
remote:        Post-processing 'CSS/style.css' failed!
remote:        Traceback (most recent call last):
remote:          File "/tmp/build_31834d76/manage.py", line 10, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 134, in collect
remote:            raise processed
remote:        whitenoise.storage.MissingFileError: The file 'CSS/images/mobile-app.png' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f8a24943cd0>.
remote:        The CSS file 'CSS/style.css' references a file which could not be found:
remote:          CSS/images/mobile-app.png
remote:        Please check the URL references in this CSS file, particularly any
remote:        relative paths which might be pointing to the wrong location.
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to trichhpali.
remote:
To https://git.heroku.com/trichhpali.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/trichhpali.git'

谢谢你的帮助

EN

回答 3

Stack Overflow用户

发布于 2021-10-31 14:48:32

Heroku不接受静态文件,您需要安装Whitenoise并将其放在设置中。

看这个医生就行了!

Whitenoise医生

Heroku Whitenoise医生

P.S:安装whitenoise之后,使用pip freeze > requirements.txt并更新请求

票数 1
EN

Stack Overflow用户

发布于 2021-10-31 17:39:45

代码语言:javascript
复制
python manage.py collectstatic

会起作用

票数 0
EN

Stack Overflow用户

发布于 2021-11-01 03:30:29

问题似乎是whitenoise.storage.MissingFileError。Whitenoise正在寻找css文件CSS/images/mobile-app.png中引用的文件CSS/style.css。因为它找不到那个文件,所以它会停止使用ValueError

解决办法是:

  1. 更新css文件(CSS/style.css)中查找CSS/images/mobile-app.png的位置。检查所引用的url路径是否正确。它可能真的需要是/images/mobile-app.png而不是CSS/images/mobile-app.png
  2. 或者添加预期丢失的文件(CSS/images/mobile-app.png)。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69787541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档