代码拉取完成,页面将自动刷新
from flask import Flask
from test import apiModel
from models.model import db
from flask_restful import Api
from register_api import api_list
def create_app(object_name):
application = Flask(__name__)
application.config.from_object(object_name)
db.init_app(application)
# 蓝图注册到app
application.register_blueprint(apiModel)
application.after_request(after_request)
# 设置请求内容的大小限制,即限制了上传文件的大小
application.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024
application = add_apis(application=application)
# 对celery进行初始化操作,可以将celery的配置写在app的配置中
# celery.init_app(app=application)
return application
# 跨域支持
def after_request(resp):
resp.headers['Access-Control-Allow-Origin'] = 'http://192.168.20.200:8090'
resp.headers['Access-Control-Allow-Credentials'] = 'true'
resp.headers['Access-Control-Allow-Methods'] = ['GET', 'POST']
resp.headers['Access-Control-Allow-Headers'] = 'x-requested-with,content-type'
return resp
def add_apis(application):
rest_api = Api()
for i in api_list:
rest_api.add_resource(i[0], i[1])
rest_api.init_app(application)
return application
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。