我使用 Python、JS、React、Django 創建了一個網站。當我通過 github 部署在 Heroku 上時,出現錯誤:
-----> Determining which buildpack to use for this app
! Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
Detected buildpacks: Python,Node.js
See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Python app detected
-----> Using Python version specified in Pipfile.lock
cp: cannot stat '/tmp/build_02d1f320/requirements.txt': No such file or directory
-----> Installing python-3.9.7
-----> Installing pip 20.2.4, setuptools 57.5.0 and wheel 0.37.0
-----> Installing dependencies with Pipenv 2020.11.15
Installing dependencies from Pipfile.lock (dee4f1)...
-----> Installing SQLite3
-----> $ python leadmanager/manage.py collectstatic --noinput
Traceback (most recent call last):
File "/tmp/build_02d1f320/leadmanager/manage.py", line 22, in <module>
main()
File "/tmp/build_02d1f320/leadmanager/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 338, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 248, in delete_file
if self.storage.exists(prefixed_path):
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 318, in exists
return os.path.exists(self.path(name))
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 38, in path
raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
! Error while running '$ python leadmanager/manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
這是我的 github 存盤庫:在此處輸入鏈接描述
當我嘗試通過 localhost:8000 運行我的網站時,它運行良好,但是現在,當我嘗試在 Heroku 上部署時,會發生此錯誤。我的資料庫是使用 django 構建的。請幫幫我,謝謝!!
uj5u.com熱心網友回復:
從錯誤回溯STATIC_ROOTurl 未配置。
您需要在 django 應用程式settings.py腳本中配置靜態檔案 dir url例如如下:STATIC_ROOT = BASE_DIR "../your-static-dir"
之后,您可以在 Heroku 上添加 run collect static 命令
heroku run python manage.py collectstatic --dry-run --noinput
還可以考慮檢查這個問題的陳述以獲取有關配置靜態和媒體 url 的更多資訊。 Django 301 和 403 禁止生產中的靜態檔案出現錯誤
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330719.html
