Files
order/application.py

39 lines
1.3 KiB
Python
Raw Normal View History

2019-07-17 16:36:59 +08:00
# -*- coding: utf-8 -*-
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
2019-07-21 18:20:01 +08:00
2025-08-27 21:11:48 +08:00
2019-07-17 16:36:59 +08:00
import os
2026-01-09 18:07:01 +08:00
# 先创建db实例
db = SQLAlchemy()
2019-07-17 16:36:59 +08:00
class Application( Flask ):
2019-07-18 08:59:26 +08:00
def __init__(self,import_name,template_folder=None,root_path = None):
super( Application,self ).__init__( import_name ,template_folder=template_folder,root_path = root_path,static_folder = None)
2019-07-17 16:36:59 +08:00
self.config.from_pyfile( 'config/base_setting.py' )
if "ops_config" in os.environ:
self.config.from_pyfile( 'config/%s_setting.py'%os.environ['ops_config'] )
2025-08-27 21:11:48 +08:00
# 设置数据库连接 URI
2026-01-09 18:07:01 +08:00
self.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:!Rjb12191@gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com:24936/food_db?charset=utf8mb4'
2025-08-27 21:11:48 +08:00
# 禁用对象修改跟踪
self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
2026-01-09 18:07:01 +08:00
# 初始化数据库
2019-07-17 16:36:59 +08:00
db.init_app( self )
2026-01-09 18:07:01 +08:00
# 创建应用实例
2019-07-18 08:59:26 +08:00
app = Application( __name__,template_folder=os.getcwd()+"/web/templates/" ,root_path = os.getcwd())
2019-07-17 16:36:59 +08:00
2019-07-18 08:59:26 +08:00
'''
函数模板
'''
from common.libs.UrlManager import UrlManager
app.add_template_global(UrlManager.buildStaticUrl, 'buildStaticUrl')
app.add_template_global(UrlManager.buildUrl, 'buildUrl')
2019-08-02 18:24:04 +08:00
app.add_template_global(UrlManager.buildImageUrl, 'buildImageUrl')
2019-07-17 16:36:59 +08:00
2025-08-27 21:11:48 +08:00