部署Flask应用程序到Heroku [英] Deploying Flask app to Heroku
问题描述
lockquote
启动过程使用命令 python run.py
2012-12-04T23:45:18 + 00:00 app [web.1]:*在
上运行 http://127.0.0.1:5000/
2012-12-04T23:45:18 + 00:00 app [web.1]:*
重新启动重新加载2012-12-04T23:45:23 + 00:00 heroku [web.1]:
错误R11(Bad bind) - >进程绑定到端口5000,应该是33507
(请参阅环境变量PORT)
我对这一切都是陌生的,但它看起来像是试图在Heroku上本地运行。我尝试了各种各样的组合,但不能得到它的工作。我现在非常简单的代码是(应用程序被称为pml):
目录:/ pml
Procfile:
web:python run.py
run.py:
from pml import app
app。 run(debug = True)
目录:/ pml / pml /
__ init __。py
from flask import Flask
app = Flask(__ name__)
导入pml.views
view.py
from pml import app
@ app.route('/')
def index():
return'Hello World!'
Heroku,但对我来说,看起来他们有一个保留的Flask端口,特别是33507.看起来它会尝试使用一个环境变量,我不知道如何在Heroku中设置。好消息是你可以告诉Flask使用哪个端口。
试试这个:
app.run(debug = True,port = 33507)
添加PORT到env中的heroku是这样做的:
$ b $ $ p $ code> heroku config:add PORT = 33507
您应该只需要执行其中一个。我会尝试第一个,对我来说,是解决这个问题的直接方法。
编辑
从你的文章中阅读文章后,我看到了问题的来源。
port = int(os.environ.get ('PORT',5000))
该行表示获取 PORT
,如果设置的话,使用5000.我不确定为什么他们不会允许它从5000运行,如果这是他们的文档,但是我会尝试这个改变:
$ p $ port = int(os.environ.get('PORT',33507))
I'm trying to develop my first "large" app with Flask on Heroku and I'm attempting to combine the basic tutorial here: https://devcenter.heroku.com/articles/python with the instructions here: http://flask.pocoo.org/docs/patterns/packages/#larger-applications. It works locally with "foreman start" but when I push to Heroku I get an error that the wrong port is in use:
Starting process with command
python run.py
2012-12-04T23:45:18+00:00 app[web.1]: * Running onhttp://127.0.0.1:5000/
2012-12-04T23:45:18+00:00 app[web.1]: * Restarting with reloader 2012-12-04T23:45:23+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 5000, should be 33507 (see environment variable PORT)
I'm new to all this, but it looks like it's trying to run "locally" on Heroku. I've tried all sorts of combinations, but can't get it to work. My very simple code right now is (the app is called "pml"):
directory: /pml
Procfile:
web: python run.py
run.py:
from pml import app
app.run(debug=True)
directory: /pml/pml/
__init__.py
from flask import Flask
app = Flask(__name__)
import pml.views
view.py
from pml import app
@app.route('/')
def index():
return 'Hello World!'
I haven't used Heroku, but to me, it looks like they have a reserved port for Flask, specifically 33507. It looks like it will try to use an environment variable, which I am not sure how to set in Heroku. The good news is you can tell Flask which port to use.
try this:
app.run(debug=True, port=33507)
and it looks like adding the PORT to the env in heroku is done like this:
heroku config:add PORT=33507
You should only have to do one of these. I would try the first as it, to me, is the straight forward way to fix the issue.
EDIT
After reading the article from your post, I see where the issue comes in.
port = int(os.environ.get('PORT', 5000))
That line says, get the value of PORT
from the environment if it is set, otherwise use 5000. I am not sure why they wouldn't allow it to run from 5000 if that's what is in their docs, but I would try this change:
port = int(os.environ.get('PORT', 33507))
这篇关于部署Flask应用程序到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!