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
posted @ 2022-06-02 13:37  楠海  阅读(34)  评论(0编辑  收藏  举报