• 226.2.flask配置文件


    1.简单配置倒入

    # coding=utf-8
    from flask import Flask
    
    app = Flask(__name__)
    # app.config.from_object("settings.DevelopmentConfig")
    
    
    @app.route("/index", methods=["POST", "GET"])
    def index():
        pass
    
    
    @app.route("/test", methods=["GET", "POST"])
    def file_test():
        '''
        获取dns服务信息接口
        '''
        import requests
        from flask import Response, stream_with_context
        options = {"headers": {"Content-Type": "application/json", "Connection": "keep-alive"}}
        resp = requests.get("http://100.64.112.114:51234/haproxy/9be20ea339934eb8.log.zip", stream=True, **options)
        response = Response(stream_with_context(resp.iter_content(chunk_size=1 * 1024 * 1024)))
        response.headers["Content-Disposition"] = "attachment; filename=%s" % "9be20ea339934eb8.log.zip"
        response.headers["Content-type"] = resp.headers['Content-type']
        response.headers['content-length'] = resp.headers['content-length']
        return response
    
    
    if __name__ == '__main__':
        app.run(debug=True)
    

    2.配置settings.py

    class BaseConfig(object):
        DEBUG = True
        TESTING = False
        DATABASE_URL = "sqlite://:memory"
    
    
    class ProductionConfig(BaseConfig):
        DEBUG = False
        DATABASE_URI = 'mysql://user@localhost/foo'
    
    
    class DevelopmentConfig(BaseConfig):
        pass
    
    
    class TestingConfig(BaseConfig):
        pass
    
  • 相关阅读:
    qt中线程的使用方法
    QT中定时器的使用方法
    Common Lisp学习笔记(八)
    Common Lisp学习笔记(七)
    Common Lisp学习笔记(六)
    vim使用笔记
    Django学习笔记:urlresolvers
    python closures and decorators
    规范命名:变量名的力量
    eclipse openGL glut运行环境配置
  • 原文地址:https://www.cnblogs.com/liuzhanghao/p/16337477.html
Copyright © 2020-2023  润新知