tornado框架最简单实现

来源:互联网 发布:网络销售干什么的 编辑:程序博客网 时间:2024/06/17 19:56


最简单的tornado服务器

官方入门入口http://demo.pythoner.com/itt2zh/index.html

#!usr/bin/env python#coding:utf-8import tornado.webimport tornado.ioloopimport tornado.optionsimport tornado.httpserverimport osimport md5import pymongofrom tornado.options import define,optionsdefine("port", default=8888, type=int)settings=dict(template_path=os.path.join(os.path.dirname(__file__), "templates"),static_path=os.path.join(os.path.dirname(__file__), "static"),debug=True,)class Application(tornado.web.Application):def __init__(self):handlers=[(r"/",LoginHandler),(),]#client=pymongo.MongoClient('localhost', 27017)#self.db=client["web"]tornado.web.Application.__init__(self, handlers, **settings)class LoginHandler(tornado.web.RequestHandler):def get(self):self.render("register.html")def post(self):usr=self.get_argument("usr", null)pwd=self.get_argument("pwd", null)web=self.application.db.webdef main():tornado.options.parse_command_line()http_server=tornado.httpserver.HTTPServer(Application())http_server.listen(options.port)tornado.ioloop.IOLoop.instance().start()if __name__=="__main__":main()


0 0
原创粉丝点击