1 #test04.py
2 import tornado.httpserver
3 import tornado.ioloop
4 import tornado.options
5 import tornado.web
6
7 from tornado.options import define,options
8
9 define('port',default=8000,help='run port',type=int)
10 define('version',default='0.0.1',help='version 0.0.1',type=str)
11 class IndexHandler(tornado.web.RequestHandler):
12 def get(self):
13 username=self.get_argument('name','no')
14 urllist=[
15 ('https://www.jd.com','京东'),
16 ('https://www.baidu.com','百度'),
17 ('https://www.zhihu.com','知乎'),
18 ]
19 atag="<a href='https://www.baidu.com' target='_blank'>__百度__</a></br>"
20 self.render('03escape.html',
21 username=username,
22 urllist=urllist,
23 atag=atag
24 )
25
26
27 if __name__ == "__main__":
28 tornado.options.parse_command_line()
29 # print(options.port)
30 app=tornado.web.Application(
31 handlers=[
32 (r'/index',IndexHandler),
33 ],
34 template_path='templates',
35 static_path='static',
36 debug=True,
37 #autoescape=None, #关闭自动转义 全局的
38 )
39 #固定写法:
40 http_server=tornado.httpserver.HTTPServer(app)
41 http_server.listen(options.port)
42 tornado.ioloop.IOLoop.instance().start()