主文件我这么写的,做了分离,配置写到config,路由写到route
,而且做了根据当前平台的环境执行不同的代码,方便本地测试和发布
#-*- coding:utf-8 -*-
import tornado.wsgi
import route
import config
import os
app = tornado.wsgi.WSGIApplication(route.route, **(config.settings))
if 'SERVER_SOFTWARE' in os.environ:
from bae.core.wsgi import WSGIApplication
application = WSGIApplication(app)
else:
class Application(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, )
if __name__ == '__main__':
app.listen(8000)
tornado.ioloop.IOLoop.instance().start()
config.py
# -*- coding: UTF-8 -*-
import os
settings = dict(
static_path=os.path.join(os.path.dirname(__file__), "static"),
template_path=os.path.join(os.path.dirname(__file__), "templates"),
)
route.py
# -*- coding: UTF-8 -*-
from controller import index
route = []
route.append((r"/",index.indexHandler))
index.py
import tornado.web
class indexHandler(tornado.web.RequestHandler):
def get(self):
self.write("hello world")
app.conf
这里主要是script,改为主文件的名字
########################## BAE application config file ######################
#
# app.conf 采用YAML格式, 请参考 http://yaml.org/
# 请尽量不要在配置部分使用中文,以免发布失败
# 请不要使用TAB键,应该使用空格
# 一定要注意对齐,否则发布会失败
# app.conf 详细功能,请参考:
# http://bce.baidu.com/doc/BAE/GUIGettingStarted.html#.E9.85.8D.E7.BD.AEapp.conf
# http://godbae.duapp.com/?p=654
#
##############################################################################
handlers:
- url : /
script: index.py
- expire : .jpg modify 10 years
- expire : .swf modify 10 years
- expire : .png modify 10 years
- expire : .gif modify 10 years
- expire : .JPG modify 10 years
- expire : .ico modify 10 years
requirements.txt
这个就比较简单了,因为没写什么功能,就加了一条,
tornado==4.4.1