增加: user = db.session.add(user) db.session.commit()
查询: User.query.filter(User.username == 'mis1114').first()
修改: user.password = '111111' db.session.commit()
删除: db.session.delete(user) db.session.commit()
from flask import Flask,render_templatefrom flask_sqlalchemy import SQLAlchemyimport configapp = 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) nickname = db.Column(db.String(50))#db.create_all()#增加数据user=User(username = 'shanshan1',password = '111111')db.session.add(user)db.session.commit()#查询数据user=User.query.filter(user.username == 'shanshan1').first()print(user.id,user.username,user.password)#修改数据user=User.query.filter(user.username == 'shanshan3').first()user.password = '0000'db.session.commit()#删除数据user=User.query.filter(user.username == 'shanshan3').first()db.session.delete(user)db.session.commit()@app.route('/')def index(): return render_template('shouye.html')@app.route( '/manhua/')def manhua(): return render_template('manhua.html')@app.route( '/login/')def login(): return render_template('denglu.html')@app.route('/register/')def register(): return render_template('zhuce.html')@app.route('/wenda/')def wenda(): return render_template('wenda.html')if __name__ == '__main__': app.run(debug=True)