1234567891011121314151617181920212223242526272829303132333435363738 |
- import logging as rel_log
- import os
- from datetime import timedelta
- from flask import Flask
- from apps.config import config
- from apps.views import init_blueprints
- def create_app(config_name = "default")->Flask:
- config_name = os.getenv('FLASK_CONFIG') or config_name
- app = Flask(config[config_name].BASE_DIR)
- # CORS(app, supports_credentials=True, resources={
- # r"/api/*": {'origins': "*"}
- # })
-
- app.config.from_object(config[config_name]) # 读取配置
- config[config_name].init_app(app)
- init_dir()
- init_blueprints(app)
- return app
- def init_dir():
- files = [
- 'uploads', 'tmp/ct', 'tmp/draw',
- 'tmp/image', 'tmp/mask', 'tmp/uploads'
- ]
- for ff in files:
- if not os.path.exists(ff):
- os.makedirs(ff)
- # @app.after_request
- # def after_request(response):
- # response.headers['Access-Control-Allow-Origin'] = '*'
- # response.headers['Access-Control-Allow-Credentials'] = 'true'
- # response.headers['Access-Control-Allow-Methods'] = 'POST'
- # response.headers['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With'
- # return response
|