[範例] 如何在Heroku上面跑Python WSGI app

看板Python作者 (S‧無限)時間14年前 (2011/09/20 19:27), 編輯推噓8(8014)
留言22則, 7人參與, 最新討論串1/1
如何在 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
不過有現階段的Paas好像都不便宜...
09/20 21:45, 3F

09/20 22:15, , 4F
我在前幾篇django GAE的有推文 這幾個PaaS包括Heroku都是有
09/20 22:15, 4F

09/20 22:16, , 5F
免費額度 就像是GAE一樣 限制或多或少 但是拿來練習或是放
09/20 22:16, 5F

09/20 22:18, , 6F
小專案倒還堪用 http://ep.io http://dotcloud.com
09/20 22:18, 6F

09/20 22:19, , 7F
其中Heroku和dotcloud是支援多語言的 可以玩混搭 :P
09/20 22:19, 7F

09/20 22:22, , 8F
dotcloud就是那個天高價格太詭異 不然不輸Heroku 前途無量
09/20 22:22, 8F

09/20 23:57, , 9F
dotcloud我也有試過 真的很棒 不過真的價格都好高阿0.0
09/20 23:57, 9F
※ 編輯: SMUGEN 來自: 120.127.47.87 (09/21 09:08)

09/21 13:11, , 10F
敢問跟GAE的不同在於??
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
歡迎大家多討論PaaS 最近百家爭鳴 然後又碰上GAE漲價...
09/23 00:22, 13F

09/23 08:52, , 14F
dotcloud 不是有 free tier 的?
09/23 08:52, 14F

09/23 11:04, , 15F
有free tier啊 我有提出來的都有 沒有free的我就暫不分享了
09/23 11:04, 15F

09/23 11:05, , 16F
只是dotcloud free tier有數目限制 不像GAE,epio,Heroku是
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
Heroku終於po了官方文章了
09/29 11:02, 19F

09/29 11:02, , 20F
blog.heroku.com/archives/2011/9/28/python_and_django/
09/29 11:02, 20F

09/29 11:02, , 21F

10/05 21:01, , 22F
推推
10/05 21:01, 22F
文章代碼(AID): #1EU7YykP (Python)
文章代碼(AID): #1EU7YykP (Python)