连接mysql数据库,创建用户模型

from flask import Flask ,render_template
from flask_sqlalchemy import SQLAlchemy
import config
app = Flask(__name__)
app.config.from_object(config)
db=SQLAlchemy(app)
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    username = db.Column(db.String(20),nullable=False)
    password = db.Column(db.String(20),nullable=False)

db.create_all()
@app.route('/')
def lx():
    return render_template('lx3.html')
@app.route('/login/',methods=['GET','POST'])
def login():
    return render_template('lx2.html')
@app.route('/regist')
def regist():
    return render_template('lx.html')
@app.route('/fabu')
def fabu():
    return render_template('fabu.html')

if __name__ == '__main__':
    app.run(debug=True)

  

原文地址:https://www.cnblogs.com/zheng01/p/7832557.html