- Heroku在翻墙后才能使用。
安装***git***
安装***virtualenv***
- 创建独立的Python环境,多个Python应用互不影响。
- 你可以先下载Pip,Python的软件安装管理包,然后
pip install virtualenv
。
- 在Heroku官网注册账号。
- 在Toolbelt下载对应系统的Heroku Toolbelt,以便你在终端里使用heroku命令行。
- 下载并安装好后,打开终端登录:
- 输入
heroku login
, 然后输入你的邮箱和密码
- 输入
1.从***Github上下载tornado heroku***样例
$ curl -L 'https://github.com/mikedory/Tornado-Heroku-Quickstart/tarball/master' | tar zx && cd mikedory-Tornado-Heroku-Quickstart-*
-
原main.py
#!/usr/bin/env python import os.path import tornado.escape import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web # import and define tornado-y things from tornado.options import define define("port", default=5000, help="run on the given port", type=int) # application settings and handle mapping info class Application(tornado.web.Application): def __init__(self): handlers = [ (r"/([^/]+)?", MainHandler) ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), debug=True, ) tornado.web.Application.__init__(self, handlers, **settings) # the main page class MainHandler(tornado.web.RequestHandler): def get(self, q): if 'GOOGLEANALYTICSID' in os.environ: google_analytics_id = os.environ['GOOGLEANALYTICSID'] else: google_analytics_id = False self.render( "main.html", page_title='Heroku Funtimes', page_heading='Hi!', google_analytics_id=google_analytics_id, ) # RAMMING SPEEEEEEED! def main(): tornado.options.parse_command_line() ***http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(tornado.options.options.port) # start it up tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main()
-
修改相应的Application类和MainHandler类并替换原static和templates文件夹中的css, js, html文件
$ virtualenv venv --distribute
$ source venv/bin/activate
4.创建***Procfile***纯文本(用sublime text或其他编辑器)
- Procfile
web: python main.py --port=$PORT
$ git init
$ git add .
$ git commit -m "init"
- 创建app在Heroku储存的空间
$ heroku create appName
- 将git中的app推向Heroku
$ git push heroku master
$heroku open