tornado框架的get方法传递参数
生活随笔
收集整理的這篇文章主要介紹了
tornado框架的get方法传递参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
tornado框架的get方法傳遞參數,代碼:
# encoding: utf-8""" @version: ?? @author: andu99 @contact: andux@qq.com @site: http://www.cnblogs.com/andu99/ @software: PyCharm @file: main.py @time: 2018/5/9 0009 上午 11:05 """from tornado.ioloop import IOLoop from tornado.httpserver import HTTPServer from tornado.options import define, options, parse_command_line from tornado.web import RequestHandler, Application# 自定義參數,下面調用這個參數http_server.listen(options.port) define('port', type=int, default=8000, help='服務器端口')class IndexHandler(RequestHandler):"""主頁處理類"""def get(self):"""get請求"""canshu1 = self.get_argument('name', 'andu99')canshu2 = self.get_arguments('name')self.write(canshu1)# self.write(str(canshu2))if __name__ == '__main__':parse_command_line()app = Application([('/', IndexHandler),], dubug=True)http_server = HTTPServer(app)http_server.listen(options.port)IOLoop.current().start()參數1 ?canshu1 的方式,self.get_argument(參數名,默認參數值) :
可以添加參數,就覆蓋了默認參數值:
get_arguments 是參數列表,輸出需要轉換成字符串列表?
?
?修改pycharm的代碼需要重新運行main.py文件。
?
轉載于:https://www.cnblogs.com/andu99/p/9013491.html
總結
以上是生活随笔為你收集整理的tornado框架的get方法传递参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中文乱码解决方案(Qt4.8.3 + Q
- 下一篇: kudu 存储引擎简析