from flask import Flask, request, render_template, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# 创建配置类
class Config:
SQLALCHEMY_DATABASE_URI="mysql+pymysql://root:123456@localhost:3306/flowerDB"
#控制台打印sql语句信息
SQLALCHEMY_ECHO=True
# 将配置类传入配置文件中,创建APP
app.config.from_object(Config)
# 将配置文件传入SQLAlchemy中,创建db对象
db=SQLAlchemy(app)
# 创建模型类
# 登录表
class Users(db.Model):
uid=db.Column(db.Integer, primary_key=True,autoincrement=True)
userd=db.Column(db.String(255), nullable=False)
passwordd=db.Column(db.String(255), nullable=False)
# 创建variety品种表(主表)
class Variety(db.Model):
vid=db.Column(db.Integer, primary_key=True,autoincrement=True)
vname=db.Column(db.String(255),nullable=False)
# 创建反查关系
flowers=db.relationship('Flowers',uselist=True,backref='variety',lazy