简体   繁体   English

heroku django Web服务器失败

[英]heroku django webserver failed

I use Procfile with web: python manage.py runserver '0.0.0.0:$PORT' first time it started successfully, but after first git push it crashed with this error: 我将Procfile与web: python manage.py runserver '0.0.0.0:$PORT'一起使用web: python manage.py runserver '0.0.0.0:$PORT' $PORT web: python manage.py runserver '0.0.0.0:$PORT'首次成功启动,但是在第一次git push它因以下错误而崩溃:

OperationalError at /

could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port 5432?

restarting webrunner did not help. 重新启动webrunner没有帮助。 What's the trick? 诀窍是什么? heroku logs output: heroku日志输出:

2013-11-25T23:39:56.725138+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
2013-11-25T23:39:56.725138+00:00 app[web.1]:     conn = _connect(dsn, connection_factory=connection_factory, async=async)
2013-11-25T23:39:56.725138+00:00 app[web.1]: OperationalError: could not connect to server: Connection refused
2013-11-25T23:39:56.725138+00:00 app[web.1]:    Is the server running on host "127.0.0.1" and accepting
2013-11-25T23:39:56.725138+00:00 app[web.1]:    TCP/IP connections on port 5432?
2013-11-25T23:39:56.725138+00:00 app[web.1]:     return Database.connect(**conn_params)
2013-11-25T23:39:56.725138+00:00 app[web.1]: 
2013-11-25T23:39:56.872620+00:00 app[web.1]: [26/Nov/2013 00:39:56] "GET / HTTP/1.1" 500 118846

using gunicorn its says that can't find gunicorn app and app[web.1]: bash: gunicorn: command not found and heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=shrouded-falls-4631.herokuapp.com fwd="188.163.187.182" dyno= connect= service= status=503 bytes= from heroku logs and heroku ps shows crashed app[web]. 使用gunicorn表示无法找到gunicorn应用程序和app[web.1]: bash: gunicorn: command not found and heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=shrouded-falls-4631.herokuapp.com fwd="188.163.187.182" dyno= connect= service= status=503 bytes=来自heroku日志,而heroku ps显示崩溃的app [web]。 Using djangos' runserver at least started at first time. 至少在第一次使用djangos的runserver。 But then also got crashed. 但是后来也坠毁了。

I do not know the exact reason, but why are you running django's runserver on heroku? 我不知道确切的原因,但是为什么要在heroku上运行django的runserver? Heroku uses gunicorn, which can execute the .wsgi files in your project_name/project_name folder. Heroku使用gunicorn,它可以执行project_name / project_name文件夹中的.wsgi文件。

Instead, use: "web: gunicorn recipe.wsgi" in the procfile, so gunicorn serves your django app. 而是在procfile中使用:“ web:gunicorn recipe.wsgi”,以便gunicorn为您的Django应用服务。 Just my 2 cents. 只是我的2美分。

Also, it seems if you use 0.0.0.0:5432 or 127.0.0.1:5432, it might work. 另外,如果您使用0.0.0.0:5432或127.0.0.1:5432,它可能会起作用。

Your database is not connected. 您的数据库未连接。 Make sure you set the proper DATABASE_URL environment variable, and that you actually have a postgres plan active. 确保设置了正确的DATABASE_URL环境变量,并且您实际上有一个激活的postgres计划。

Thanks @user2707389, it really works only with all apps declared in requirements.txt but I don't get it why it doesn't with -r option. 感谢@ user2707389,它实际上仅适用于在requirements.txt声明的所有应用程序,但是我不明白为什么它不带有-r选项。 Anyway, fixing further Procfile and correct wsgi.py made it alive. 无论如何,进一步修复Procfile并更正wsgi.py使其活着。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM