為什麼這篇heroku免費額度鄉民發文收入到精華區:因為在heroku免費額度這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者SMUGEN (S‧無限)看板Python標題[範例] 如何在Heroku上面跑Python W...
如何在 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