我在做什么 ?
- 我正在嘗試在 heroku 服務器上部署一個 django web 應用程式。
問題
我無法使用 .css 在 heroku 服務器中推送 css 檔案
git push heroku main。當我從靜態檔案夾中洗掉 css 檔案時,一切都很順利。
更多的
- 我也安裝了whitenoise.....
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'
謝謝你的幫助??
uj5u.com熱心網友回復:
Heroku 不接受靜態檔案,您需要安裝 Whitenoise 并將其放入設定中。
看到這個檔案,它會作業!
白噪聲檔案
Heroku Whitenoise 檔案
PS:安裝 whitenoise 后,使用pip freeze > requirements.txt并更新您的要求
uj5u.com熱心網友回復:
python manage.py collectstatic
會作業
uj5u.com熱心網友回復:
問題似乎是whitenoise.storage.MissingFileError。Whitenoise 正在尋找CSS/images/mobile-app.png在您的 css 檔案中參考的檔案CSS/style.css。因為它找不到那個檔案,所以它以ValueError.
解決方案是:
更新您的 css 檔案 (
CSS/style.css) 中要查找的位置CSS/images/mobile-app.png。檢查參考它的 url 路徑是否正確。例如,它可能真的需要/images/mobile-app.png代替CSS/images/mobile-app.png.或者將丟失的檔案添加到預期的位置 (
CSS/images/mobile-app.png)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/343438.html
下一篇:將手電筒添加到離子反應專案
