您的位置:首页 > 其它

tornado框架最简单实现

2015-08-28 14:41 309 查看
最简单的tornado服务器

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

#!usr/bin/env python
#coding:utf-8

import tornado.web
import tornado.ioloop
import tornado.options
import tornado.httpserver
import os
import md5
import pymongo

from tornado.options import define,options
define("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.web

def 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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: