Heroku 上應用 Flask-Script


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Profile 的內容
# - host 指定為 0.0.0.0 即監聽所有事
# - port 指定為 Heroku 給的 $PORT 環境變量
web: python app.py runserver --host=0.0.0.0 --port=$PORT

# manager.py 的內容
# - 因為由 Profile 啟動與指定,所以要自定 runserver 指令
manager.add_command("runserver", Server())

# 完整內容大約就是這樣 (根據我的應用例子來說)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask.ext.script import Manager, Server
from app.app import create_app

app = create_app()

manager = Manager(app)
manager.add_command("runserver", Server())

@manager.command
def createdb():
"""Create database."""
from app.models import db
db.create_all()

if __name__ == "__main__":
manager.run()

參考