1. 程式人生 > >tornado多路由示例

tornado多路由示例

con src self. style class help QQ ons com

main.py代碼:

# encoding: utf-8


"""
@version: ??
@author: andu99
@contact: [email protected]
@site: http://www.cnblogs.com/andu99/
@software: PyCharm
@file: main.py
@time: 2018/5/9 0009 上午 11:05
"""

import tornado.web
import tornado.ioloop
import tornado.httpserver
import tornado.options

from tornado.options import
define, options from tornado.web import RequestHandler, url # 自定義參數,下面調用這個參數http_server.listen(options.port) define(port, type=int, default=8000, help=服務器端口) class IndexHandler(tornado.web.RequestHandler): """主頁處理類""" def get(self): """get請求""" self.write(<a href="
+ self.reverse_url(a_url) + ">這是鏈接</a>) class SubjectHandler(RequestHandler): def initialize(self, subject): self.subject = subject def get(self): self.write(self.subject) if __name__ == __main__: tornado.options.parse_command_line() app = tornado.web.Application([ (
/, IndexHandler), (/learn, SubjectHandler, {subject: 學習python的tornado框架}), url(/a, SubjectHandler, {subject: 點擊鏈接後的內容}, name=a_url), ], dubug=True) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) tornado.ioloop.IOLoop.current().start()

點擊運行:

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

tornado多路由示例