tornado-MainHandler(RequestHandler) 中get参数api值一直是空
源码:
import json
import tornado.ioloop
import tornado.web
from tornado.web import RequestHandler , Application
class MainHandler(RequestHandler):
def get(self , api=""):
"""
根据用户请求的api,返回对应的数据
:param api : 用户请求的应用接口
"""
print("api is " , api)
if not api:
links = ["random" , "names" , "proxies" , "all" , "count"]
self.write("<h4>welcome to adsl api!</h4>")
for link in links:
self.write("<a href={link}> {link}</a><br/>".format(link=link))
def server(port=8000 , address=""):
"""
创建启动web服务器框架
"""
app = Application([
(r"/" , MainHandler) ,
(r"/.*" , MainHandler)
])
app.listen(port=port , address=address)
print("adsl api listen on " , port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
server()