Flask SQLAlchemy 脚本测试方法

app / db上下文 环境中测试脚本

1
2
3
4
5
6
7
8
9
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
with app.app_context():
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///~/work/TowerMonitor/TMService/db/global.db'
db = SQLAlchemy(app)

if __name__ == '__main__':