bae部署tornado demo

主文件我这么写的,做了分离,配置写到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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bwlab

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值