Flask应用程序无法在Heroku服务器上启动 [英] Flask app dont start on heroku server

查看:85
本文介绍了Flask应用程序无法在Heroku服务器上启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Heroku部署Flask应用.这是简单的API.在heroku上启动时,我在工头上工作得很好,但是出现错误(下面是日志).

I'm trying to deploy a Flask app with Heroku. It's simple API. Works great local with foreman but I get error (log is below) when starts on heroku.

这是我的应用程序代码(我知道这是一个小块,但我很难将其拆分为文件):

This is my app code (I know it's but looking in one block, but I have problems to split it to files):

import flask
import flask.ext.sqlalchemy
import flask.ext.restless

app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://user:password@server/db'
db = flask.ext.sqlalchemy.SQLAlchemy(app)


from sqlalchemy import Column, Integer, String, ForeignKey,\
    Date, DateTime, Boolean, Float


class fruits(db.Model):
    __tablename__ = 'fruits'
    id = Column(Integer, primary_key=True)
    name = Column(String(50),nullable=False)
    calories = Column(Integer, nullable=False)
    amount = Column(Integer, nullable=False)
    unit = Column(String(10),nullable=False)
    url = Column(String(100),nullable=True)


@app.route('/')
def hello_world():
    return 'Hello World!'


# Create the database tables.
db.create_all()

# Create the Flask-Restless API manager.
manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)

# Create API endpoints, which will be available at /api/<tablename> by
# default. Allowed HTTP methods can be specified as well.
manager.create_api(fruits, methods=['GET', 'POST', 'DELETE'])
manager.create_api(tmp, methods=['GET', 'POST', 'DELETE'])


# start the flask loop

if __name__ == '__main__':
        import os  
        port = int(os.environ.get('PORT', 33507)) 
        app.run(host='0.0.0.0', port=port)

这是heroku日志:

This is heroku log:

at=error code=H14 desc="No web processes running" method=GET path=/ host=blooming-taiga-1210.herokuapp.com fwd="188.33.19.82" dyno= connect= service= status=503 bytes=

和我的Procfile:

and my Procfile:

web: python __init__.py

推荐答案

实际上是否存在一个名为web的正在运行的dyno?看来您可能已经忘记了缩放您的Web dyno :

Is there actually a running dyno called web? It looks like you might have forgotten to scale your web dyno:

在Procfile中添加这样的条目:

Add an entry like this in your Procfile:

heroku ps:scale web=1

您可以使用

heroku ps

确认您的web dyno正在运行.

to confirm that your web dyno is running.

这篇关于Flask应用程序无法在Heroku服务器上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆