zoukankan      html  css  js  c++  java
  • tornado设置settings

    1.作用
    设置应用程序相关参数

    2.用法

    settings = dict()
    settings["debug"] = True
    tornado.web.Application.__init__(self, handlers, **settings)
    

    3.相关参数详解
    1)debug
    设置应用程序为debug模式,debug模式下,修改了.py文件后,application会自动重启。
    或者在.py文件中引入自动启动包 import tornado.autoreload
    在部署正式时,需将debug=False,可加快执行速度。

    2)log_function
    自定义日志输出格式
    tornado定义了三种日志处理器,access_log,app_log,gen_log
    通过定义log_function函数,可以自定义输出格式

    def log_func(handler):
        if handler.get_status() < 400:
            log_method = access_log.info
        elif handler.get_status() < 500:
            log_method = access_log.warning
        else:
            log_method = access_log.error
        request_time = 1000.0 * handler.request.request_time()
        log_method("%d %s %s (%s) %s %s %.2fms",
                   handler.get_status(), handler.request.method,
                   handler.request.uri, handler.request.remote_ip,
                   handler.request.headers["User-Agent"],
                   handler.request.arguments,
                   request_time)
    settings["log_function"] = log_func
    
    

    3)static_path
    静态文件路径

    4)static_url_prefix
    静态文件url前缀

    5)template_path
    模板文件路径

    6)gzip
    设置gzip压缩

  • 相关阅读:
    枚举
    泛型
    装箱和拆箱
    使用TryParse()来执行数值转换
    参数数组
    checked和unchecked转换
    字符串不可变
    TCC : Tiny C Compiler (2018-2-6)
    win10 下 protobuf 与 qt
    QWebView 与Js 交互
  • 原文地址:https://www.cnblogs.com/shijingjing07/p/7699124.html
Copyright © 2011-2022 走看看