Python 在heroku中没有运行Django的Web进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18552846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:03:10  来源:igfitidea点击:

No web processes running Django in heroku

pythondjangoherokudeployment

提问by Cris Towi

I was trying to deploy my application in heroku, but when i finally try to run my application in heroku I het in the browser this:

我试图在 heroku 中部署我的应用程序,但是当我最终尝试在 heroku 中运行我的应用程序时,我在浏览器中显示:

Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

When i see my logs I get the next:

当我看到我的日志时,我得到了下一个:

2013-08-31T19:53:30.672416+00:00 heroku[api]: Enable Logplex by [email protected]
2013-08-31T19:53:30.700218+00:00 heroku[api]: Release v2 created by [email protected]
2013-08-31T19:58:41+00:00 heroku[slug-compiler]: Slug compilation started
2013-08-31T20:04:12.967456+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=502 bytes=
2013-08-31T20:04:13.161016+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=502 bytes=
2013-08-31T20:13:46+00:00 heroku[slug-compiler]: Slug compilation timed out: 904.285527871 seconds.
2013-08-31T20:22:52.646361+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=502 bytes=
2013-08-31T20:22:55.043424+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=502 bytes=
2013-08-31T20:26:14+00:00 heroku[slug-compiler]: Slug compilation started
2013-08-31T20:38:41+00:00 heroku[slug-compiler]: Slug compilation started
2013-08-31T20:41:22+00:00 heroku[slug-compiler]: Slug compilation timed out: 908.241350492 seconds.
2013-08-31T20:49:24.238496+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=502 bytes=
2013-08-31T20:49:24.644910+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=502 bytes=
2013-08-31T20:53:47+00:00 heroku[slug-compiler]: Slug compilation timed out: 907.148099965 seconds.
2013-08-31T20:56:59+00:00 heroku[slug-compiler]: Slug compilation started
2013-08-31T20:58:50.641624+00:00 heroku[api]: Attach HEROKU_POSTGRESQL_AQUA resource by [email protected]
2013-08-31T20:58:50.658435+00:00 heroku[api]: Release v3 created by [email protected]
2013-08-31T20:58:50.742803+00:00 heroku[api]: Add DATABASE_URL config by [email protected]
2013-08-31T20:58:50.782484+00:00 heroku[api]: Release v4 created by [email protected]
2013-08-31T20:58:50.840509+00:00 heroku[api]: Deploy 78dba6c by [email protected]
2013-08-31T20:58:50.852187+00:00 heroku[api]: Release v5 created by [email protected]
2013-08-31T20:58:54+00:00 heroku[slug-compiler]: Slug compilation finished
2013-08-31T21:00:25.085053+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
2013-08-31T21:00:24.751074+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
2013-08-31T21:01:03.272614+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
2013-08-31T21:01:03.815558+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
2013-08-31T21:02:10.279054+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
2013-08-31T21:03:25.381362+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
2013-08-31T21:03:25.709121+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
2013-08-31T21:03:45.285962+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=503 bytes=
christian@christian-R480-R431-R481:~/Documentos/heroku/portafolio/venv$ 

回答by Benjamin Manns

Have you gone through the Heroku guide for setting up a Django application? What does your Procfile look like?

您是否阅读过Heroku 指南以设置 Django 应用程序?你的 Procfile 是什么样的?

Your project should have a file named Procfilethat should have contents similar to

您的项目应该有一个名为的文件Procfile,该文件的内容类似于

web: gunicorn hellodjango.wsgi

回答by ecoe

Benjamin Manns' solution worked for me, though I needed one additional step as well.

Benjamin Manns 的解决方案对我有用,但我还需要一个额外的步骤。

According to this, after the Procfilesolution has been pushed, run the following:

根据,在之后Procfile的解决方案已被推,运行以下命令:

heroku ps:scale web=1

heroku ps:scale web=1

website should load correctly now.

网站现在应该可以正确加载。

for more help pushing to a heroku git repo, see this

有关推送到 heroku git repo 的更多帮助,请参阅

回答by Savad KP

Add proc file and run following command

添加proc文件并运行以下命令

$ heroku ps:scale web=1

$ heroku ps:scale web=1

回答by Shekh Ataul

Your Procfilemust look like this (for python):

您的Procfile必须如下所示(对于 python):

web: python myApp.py runserver 0.0.0.0:$PORT

网络:python myApp.py runserver 0.0.0.0:$PORT

回答by Shinto Joseph

If you are in python/django

如果你在 python/django

heroku logs --tail

if you are unable to find the bug and fix then try doing,

如果您无法找到错误并修复,请尝试执行,

First Run to see whether its working in herokus local

首先运行看看它是否在herokus本地工作

heroku local web

Mine was to specify the path of django wsgi.py file in Procfile

我的是在Procfile中指定django wsgi.py文件的路径

see their example https://github.com/heroku/python-getting-started

看他们的例子https://github.com/heroku/python-getting-started

The Procfile will look similar to this

Procfile 将与此类似

web: gunicorn projectname.wsgi --log-file -

You may have to install gunicorn if not installed and add it to requirements.txt

如果未安装,您可能需要安装 gunicorn 并将其添加到 requirements.txt

Then Git add and commit, after that push to heroku

然后 Git 添加并提交,然后推送到 heroku

git push heroku master

Then scale your app

然后扩展您的应用程序

heroku ps:scale web=1

回答by cegprakash

I did the following steps to make it work.

我做了以下步骤来使它工作。

1) I had to move my Procfile to the outermost folder.

1)我不得不将我的 Procfile 移动到最外面的文件夹。

2) Then I had to change my Procfile to

2)然后我不得不将我的 Procfile 更改为

web: gunicorn projectname.projectname.wsgi

3) Also in my wsgi file I had to change my settings path to

3) 同样在我的 wsgi 文件中,我必须将设置路径更改为

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.projectname.settings')

4) In my settings.py file I had to change my ROOT_URLCONF

4) 在我的 settings.py 文件中,我必须更改我的 ROOT_URLCONF

ROOT_URLCONF = 'projectname.projectname.urls'

5) In urls.py I had to change my path to

5) 在 urls.py 中,我必须将路径更改为

from projectname.applicationname import urls as app_urls

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(app_urls)),
]

6) Finally I did

6)最后我做到了

git push heroku master
heroku ps:scale web=1

After making all these changes heroku worked like a charm. But it doesn't work locally on windows because I read somewhere windows doesn't have gunicorn.

完成所有这些更改后,heroku 工作起来很有吸引力。但它不能在 Windows 本地工作,因为我在某个地方读到 Windows 没有 gunicorn。

When I tried python projectname/manage.py runserverlocally it said

当我python projectname/manage.py runserver在本地尝试时,它说

ModuleNotFoundError: No module named 'projectname.projectname'

So for running it locally I've to revert all the steps above :P

所以为了在本地运行它,我必须恢复上面的所有步骤:P