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