通过用户模型,对数据库进行增删改查操作。
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() user=User(username='mis777789',password='g6666') db.session.add(user) db.session.commit() user = User.query.filter(User.username=='mis777789').first user.password='0.0.0.0' db.session.commit() user = User.query.filter(User.username=='mis777789').first() db.session.delete(user) db.session.commit() @app.route('/') def index(): return render_template("l") if __name__ == '__main__': app.run(debug=True)