赞
踩
python代码 # 导入需要的模块 from flask import * from flask_sqlalchemy import SQLAlchemy # 创建 Flask 应用实例 app = Flask(__name__) # 配置数据库连接信息 class Config: SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:123456@localhost:3306/cardDB' SQLALCHEMY_ECHO = True # 加载配置信息 app.config.from_object(Config) # 创建数据库实例 db = SQLAlchemy(app) # 定义 从表 class Cards(db.Model): __tablename__ = 'cards' cid = db.Column(db.Integer, primary_key=True, autoincrement=True) cnumber = db.Column(db.String(20), default=18900000000, nullable=False, unique=False) cPIN = db.Column(db.Integer, nullable=False, unique=False) cstate = db.Column(db.Integer, nullable=False) oid = db.Column(db.Integer, db.ForeignKey('operator.oid'), nullable=False) # 定义 主表 class Operator(db.Model): oid = db.Column(db.Integer, primary_key=True, autoincrement=True) oname = db.Column(db.String(255), nullable=False) # 定义关系 cards = db.relationship('Cards', backref='operator', uselist=True, lazy='dynamic') # 创建表 @app.route('/') def create_table(): db.create_all() return '建表成功' # 查询 @app.route('/query', methods=['GET', 'POST']) def query(): if reques
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。