[範例] 如何在Heroku上面跑Python WSGI app
如何在 Heroku 上面跑 Python WSGI app
以我的狀況為例,使用 Windows 且沒用過 Ruby
1. 安裝 Ruby
http://rubyinstaller.org/
2. 安裝 Gem (類似 Python 的 pip )
http://docs.rubygems.org/read/chapter/3
3. 安裝 Heroku CLI
http://devcenter.heroku.com/articles/heroku-command
4. 註冊 Heroku
https://api.heroku.com/signup
5. 產生專案檔案
R:\>mkdir heroku-python
R:\>cd heroku-python
5.1 requirements.txt ( pip requirements 讓 Heroku 認出這是 Python 專案)
Flask
tornado
5.2 app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
5.3 server.py
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from app import app
from os import environ
if __name__ == "__main__":
http_server = HTTPServer(WSGIContainer(app))
http_server.bind(environ.get("PORT", 80))
http_server.start(1)
IOLoop.instance().start()
5.4 Procfile ( http://devcenter.heroku.com/articles/procfile )
web: ./bin/python server.py
6. Git 它
git init
git add .
git commit -m "Python WSGI app on Heroku"
7. Heroku 它
heroku create --stack cedar
8. push 它
git push heroku master
9. DONE!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.116.61.125
推
09/20 21:38, , 1F
09/20 21:38, 1F
推
09/20 21:44, , 2F
09/20 21:44, 2F
推
09/20 21:45, , 3F
09/20 21:45, 3F
→
09/20 22:15, , 4F
09/20 22:15, 4F
→
09/20 22:16, , 5F
09/20 22:16, 5F
→
09/20 22:18, , 6F
09/20 22:18, 6F
→
09/20 22:19, , 7F
09/20 22:19, 7F
→
09/20 22:22, , 8F
09/20 22:22, 8F
推
09/20 23:57, , 9F
09/20 23:57, 9F
※ 編輯: SMUGEN 來自: 120.127.47.87 (09/21 09:08)
推
09/21 13:11, , 10F
09/21 13:11, 10F
→
09/21 13:25, , 11F
09/21 13:25, 11F
推
09/22 17:40, , 12F
09/22 17:40, 12F
→
09/23 00:22, , 13F
09/23 00:22, 13F
推
09/23 08:52, , 14F
09/23 08:52, 14F
→
09/23 11:04, , 15F
09/23 11:04, 15F
→
09/23 11:05, , 16F
09/23 11:05, 16F
→
09/23 11:07, , 17F
09/23 11:07, 17F
→
09/23 13:05, , 18F
09/23 13:05, 18F
→
09/29 11:02, , 19F
09/29 11:02, 19F
→
09/29 11:02, , 20F
09/29 11:02, 20F
→
09/29 11:02, , 21F
09/29 11:02, 21F
推
10/05 21:01, , 22F
10/05 21:01, 22F
Python 近期熱門文章
PTT數位生活區 即時熱門文章