标签:query class word com integer pre bsp use creat
增加: 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()
1 from flask import Flask 2 from flask_sqlalchemy import SQLAlchemy 3 import config 4 5 app = Flask(__name__) 6 app.config.from_object(config) 7 8 db=SQLAlchemy(app) 9 10 class User(db.Model): 11 __tablename__ = ‘User‘ 12 id = db.Column(db.Integer,primary_key=True,autoincrement=True) 13 username = db.Column(db.String(20),nullable=False) 14 password = db.Column(db.String(20),nullable=False) 15 nickname = db.Column(db.String(20)) 16 #db.create_all() 17 18 #增 19 user=User(username=‘liu1234‘,password=‘123456789‘) 20 db.session.add(user) 21 db.session.commit() 22 #删 23 user=User.query.filter(User.username==‘two1234‘).first() user.password=‘12345678910‘ 24 db.session.delete(user) 25 db.session.commit() 26 #改 27 user=User.query.filter(User.username==‘two1234‘).first() 28 user.username=‘three1234‘ 29 db.session.add(user) 30 db.session.commit() 31 #查 32 user=User.query.filter(User.username==‘two1234‘).first() 33 print(user.id,user.username,user.password) 34 35 @app.route(‘/‘) 36 def hello_world(): 37 return ‘Hello World!‘ 38 39 40 if __name__ == ‘__main__‘: 41 app.run()
增:
删:
改:
查:
标签:query class word com integer pre bsp use creat
原文地址:http://www.cnblogs.com/lkm123/p/7850632.html