ormapp.py
from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy ormapp = Flask(__name__) print('ormapp是否执行',type(ormapp)) # 配置链接参数 ormapp.config['SQLALCHEMY_DATABASE_URI']='mysql://root:a123@127.0.0.1:3306/learning' db = SQLAlchemy(ormapp) # 绑定到flask对象 print('测试值ormapp') # ORM模型创建 class User(db.Model): __tablename__ = 'user_test' id = db.Column(db.Integer,primary_key=True) username = db.Column(db.String(64),nullable=False) password = db.Column(db.String(256),nullable=False) birth_date = db.Column(db.String(256),nullable=True) age = db.Column(db.Integer,default=0) class UserAddress(db.Model): __tablename__ = 'user_addr' id = db.Column(db.Integer, primary_key=True) addr = db.Column(db.String(256),nullable=False) user_id = db.Column(db.Integer,db.ForeignKey('user_test.id