日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Tornado 使用手册(一)---------- 简单的tornado配置

發布時間:2023/12/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tornado 使用手册(一)---------- 简单的tornado配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

#Tornado 使用手冊(一)---------- 簡單的tornado配置

1. 簡單的web.py

import tornado.ioloopimport tornado.webimport osfrom tornado.options import options, defineclass MainHandler(tornado.web.RequestHandler):def get(self):self.write("hello,world")settings = {'debug': True,'gzip': True,'autoescape': None,'xsrf_cookies': False,'cookie_secret': 'xxxx'}application = tornado.web.Application([(r'/', MainHandler)])if __name__ == '__main__':application.listen(9002)tornado.ioloop.IOLoop.instance().start()

##2. debug 參數配置

settings = {'debug': True, # 開發模式'gzip': True, # 支持gzip壓縮'autoescape': None,'xsrf_cookies': False,'cookie_secret': 'xxx'}application = tornado.web.Application([(r'/', MainHandler)], **settings)

##3. 默認參數配置

# 在tornado.options.options配置變量名from tornado.options import define, optionsdefine('debug', default=True, help='enable debug mode')define('project_path', default=sys.path[0], help='deploy_path')define('port', default=8888, help='run on this port', type=int)# 從命令行中解析參數信息, 如 python web.py --port=9002, 這里的port解析tornado.options.parse_command_line()

##4. 使用參數

使用options獲取剛設置的參數from tornado.options import options....application.listen(options.port).....settings = {'debug': options.debug,}

##5. 完整代碼

#!/usr/bin/env python# -*- coding: utf-8 -*-# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:__author__ = 'okker.ma@gmail.com'import tornado.ioloopimport tornado.webimport osfrom tornado.options import options, define#在options中設置幾個變量define('debug', default=True, help='enable debug mode')define('port', default=9002, help='run on this port', type=int)# 解析命令行, 有了這行,還可以看到日志...tornado.options.parse_command_line()class MainHandler(tornado.web.RequestHandler):def get(self):self.write("hello,a world")settings = {'debug': options.debug,'gzip': True,'autoescape': None,'xsrf_cookies': False,'cookie_secret': 'xxxxxxx'}application = tornado.web.Application([(r'/', MainHandler)], **settings)if __name__ == '__main__':application.listen(options.port)tornado.ioloop.IOLoop.instance().start()

運行:

python web.py --port=9002 --debug=True

轉載于:https://my.oschina.net/jiemachina/blog/204875

總結

以上是生活随笔為你收集整理的Tornado 使用手册(一)---------- 简单的tornado配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。