tornado路由系统
在web框架中,路由表中的任何项都是一个元组,每个元组都包含模式和处理程序。当httpserver收到http请求时,服务器从收到的请求中解析url路径(在http协议开始行中),然后顺序遍历路由表。如果url路径可以匹配模式,则http请求将发送到web应用程序中的相应处理程序进行处理。
由于url路由机制,web应用程序开发人员不必处理复杂的http服务器层代码,只需编写web应用程序层(处理程序)的逻辑即可。Tornado中的每个url都对应一个类。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__auth__ = "zhangyanlin"
import tornado.web
import tornado.ioloop
class IndexHandler(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
self.write("Hello World, My name is 张岩林")
class LoginHandler(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
self.write("<input type = 'text'>")
class RegisterHandler(tornado.web.RequestHandler):
def get(self, *args