tornado建立路由
阿新 • • 發佈:2018-11-07
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.write('hello') #在頁面輸出“hello"。
#返回 HTML
class TemHandler(tornado.web.RequestHandler):
def get(self):
self.render('01in_out.html') #”01in_out.html“為專案中的html檔案,可自己編寫
if __name__ == '__main__':
tornado.options.parse_command_line()
app = tornado.web.Application(
handlers=[
(r'/',IndexHandler),
(r'/',TemHandler),
]
)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()