直接上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import asyncio
import tornado.web


class txtPathHandler(tornado.web.RequestHandler):
def get(self, path):
print('this', path)
self.write("Hello, world")


class comPathHandler(tornado.web.RequestHandler):
def get(self, path):
print('this', path)
# print(dir(self))
print(self.request.method)
print(self.request.uri)
print(self.request.host)
self.write("Hello, com")


application = tornado.web.Application([
# (r"/", MainHandler),
(r"/(.*)", txtPathHandler),
])

application.add_handlers(r"(.*)$", [
(r"/(.*)", comPathHandler),
])

if __name__ == "__main__":
application.listen(8888)
# tornado.ioloop.IOLoop.instance().start()
loop = asyncio.get_event_loop()
loop.run_forever()