1 Star 0 Fork 0

shulj/python-Flask

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
application.py 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
shulj 提交于 2019-12-09 12:01 . '1'
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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/shulj/python-Flask.git
[email protected]:shulj/python-Flask.git
shulj
python-Flask
python-Flask
master

搜索帮助