__init__.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import logging as rel_log
  2. import os
  3. from datetime import timedelta
  4. from flask import Flask
  5. from apps.config import config
  6. from apps.views import init_blueprints
  7. def create_app(config_name = "default")->Flask:
  8. config_name = os.getenv('FLASK_CONFIG') or config_name
  9. app = Flask(config[config_name].BASE_DIR)
  10. # CORS(app, supports_credentials=True, resources={
  11. # r"/api/*": {'origins': "*"}
  12. # })
  13. app.config.from_object(config[config_name]) # 读取配置
  14. config[config_name].init_app(app)
  15. init_dir()
  16. init_blueprints(app)
  17. return app
  18. def init_dir():
  19. files = [
  20. 'uploads', 'tmp/ct', 'tmp/draw',
  21. 'tmp/image', 'tmp/mask', 'tmp/uploads'
  22. ]
  23. for ff in files:
  24. if not os.path.exists(ff):
  25. os.makedirs(ff)
  26. # @app.after_request
  27. # def after_request(response):
  28. # response.headers['Access-Control-Allow-Origin'] = '*'
  29. # response.headers['Access-Control-Allow-Credentials'] = 'true'
  30. # response.headers['Access-Control-Allow-Methods'] = 'POST'
  31. # response.headers['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With'
  32. # return response