gpt4 book ai didi

python - 为什么我的 Django 应用程序可以在本地运行,但不能在 Heroku 上运行?

转载 作者:太空宇宙 更新时间:2023-11-04 10:44:56 26 4
gpt4 key购买 nike

My Django app在本地工作正常,有时推送到 Heroku 是成功的,但 heroku 日志显示错误(并且应用程序无法在线加载)。我的 Procfile 似乎有问题(或者可能是我的 virtualenv,尽管我已经重新完成了整个工作以尝试修复它)。

我在我的 Procfile 中尝试了很多版本:

web: python manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT proj/prod_settings.py

还有这个:

web: python manage.py runserver 0.0.0.0:$PORT collectstatic --noinput
--settings=proj/prod_settings.py

还有这个:

web: gunicorn bookfairy.wsgi.py

但我不断收到这样的错误:

-foreman start pid 17199 result: no such option: --noinput

-foreman start pid 17229 result: no such option: --workers

-foreman start pid 17299 result: Could not import settings 'proj/prod_settings.py' (Is it on sys.path?): Import by filename is not supported.
-Push failed: slug archive could not be created
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to heroku
-foreman start pid 16943 result: Error: Usage is runserver [optional port number, or ipaddr:port]
-Process exited with status 1
State changed from starting to crashed
-heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/robots.txt host=bookfairy.herokuapp.com fwd="66.249.72.200" dyno= connect= service= status=503 bytes=
-heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/robots.txt host=bookfairy.herokuapp.com fwd="173.199.115.131" dyno= connect= service= status=503 bytes=

还有这个:

    File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 317, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
self.connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

我能想到的我尝试过的事情:

  • 删除并替换了我的 Procfile(大写,是的)
  • 完成对我的 requirements.txt 文件的 pip 卡住
  • 添加了一个 runtime.txt 文件
  • 开始测功
  • 遵循所有 Heroku Django 说明
  • 重新安排了我的目录结构(并将我的 wsgi.py 文件移动到与要求.txt)
  • 尝试过 run_gunicorn(未知命令错误)
  • 点子安装了所有依赖项(两次,包括 Django、psycopg2、dj-数据库-url)
  • heroku 运行 python manage.py syncdb(服务器是否在主机“localhost”(127.0.0.1) 上运行并在端口 5432 上接受 TCP/IP 连接?)
  • 检查 Postgres 和 Heroku 工具带安装

如果能得到一些帮助,我将不胜感激。

最佳答案

命令 python manage.py runserver 0.0.0.0:$PORT collectstatic --noinput 无效,您正在尝试将两件事合而为一。

python manage.py runserver 0.0.0.0:$PORT

python manage.py collectstatic --noinput

将它们分解为单独的命令,我建议将 runserver 放入 Procfile 并在 shell 中运行 collectstatic

关于python - 为什么我的 Django 应用程序可以在本地运行,但不能在 Heroku 上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18091022/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com