app.py 694 B

12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Quart
  5. from server.routes import Routes
  6. from applications.db import AsyncMySQLClient
  7. from applications.config import Config
  8. # 初始化 App
  9. app = Quart(__name__, static_folder='applications/static')
  10. config = Config(env="copy1")
  11. # 注册连接池
  12. AsyncMySQL = AsyncMySQLClient(app)
  13. app_routes = Routes(AsyncMySQL, config)
  14. app.register_blueprint(app_routes)
  15. @app.before_serving
  16. async def init_db():
  17. """
  18. 初始化
  19. :return:
  20. """
  21. await AsyncMySQL.initPool()
  22. @app.after_serving
  23. async def close_db():
  24. """
  25. 关闭连接
  26. :return:
  27. """
  28. await AsyncMySQL.closePool()
  29. if __name__ == '__main__':
  30. app.run(debug=True)