tornado 第二种路由方法(装饰器)

#!/usr/bin/env python
# _*_coding:utf-8 _*_

import tornado.ioloop
import tornado.web

application = tornado.web.Application([])

def decorator(view):
    URL = view.URL
    application.add_handlers('.*$', [(r'%s' % (URL), view)])

@decorator
class UserstHandler(tornado.web.RequestHandler):
    URL = '/users'

    def get(self, *args, **kwargs):
        self.write("UserstHandler")

@decorator
class IndexHandler(tornado.web.RequestHandler):
    URL = '/'

    def get(self, *args, **kwargs):
        self.write("IndexHandler")

if __name__ == "__main__":
    application.listen(8000)
    print("http://127.0.0.1:8000")
    tornado.ioloop.IOLoop.instance().start()

 

posted @ 2016-12-09 15:06  我当道士那儿些年  阅读(743)  评论(0编辑  收藏  举报