tornado框架最简单实现


最简单的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()


你可能感兴趣的:(tornado)