1.安装依赖
pip3 install flask_sqlalchemy -i https://mirrors.aliyun.com/pypi/simple/ requests
2.数据库配置信息(db_manager.py)
import os
from flask import Flask
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
database = 'test'
app = Flask(__name__)
# 设置文件上传大小限制为500MB
app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024
CORS(app)
if os.path.exists('/root'):
app.config[
'SQLALCHEMY_DATABASE_URI'] = f'mssql+pyodbc://root:123456@127.0.0.1:3433/{database}?driver=ODBC+Driver+17+for+SQL+Server&charset=utf8'
else:
app.config[
'SQLALCHEMY_DATABASE_URI'] = f'mssql+pyodbc://root:123456@127.0.0.1:1433/{database}?driver=SQL+Server'
db = SQLAlchemy(app)
3.数据表对象
# -*- coding: utf-8 -*-
# ====> 配置管理中心 <==== #
from datetime import datetime
from db_manager import db
# 配置分组
class AISConfGroup(db.Model):
id = db.Column(db.Integer, primary_key=True)
create_time = db.Column(db.DateTime, default=datetime.now)
modify_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
parent_code = db.Column(db.String(50))
code = db.Column(db.String(50))
name = db.Column(db.String(50))
type_c = db.Column(db.String(50))