标签:col ssi integer object session 连接 用户 column ring
增加:
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
from flask_sqlalchemy import SQLAlchemy
import connect
app = Flask(__name__)
app.config.from_object(connect)#app连接数据库
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ =‘user1‘
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)
againpass = db.Column(db.String(20), nullable=False)
#db.create_all()
#增加
user=User(username=‘111‘,password=‘222‘)
db.session.add(user)
db.session.commit()
#查找
user=User.query.filter(User.username==‘two1234‘).first()
print(user.id,user.username,user.password)
#修改
user=User.query.filter(User.username == ‘mis1234‘).first()
user.password = ‘22222‘
db.session.commit()
print(user.id,user.username,user.password)
#删除
user=User.query.filter(User.username==‘two1234‘).first() user.password=‘12345678910‘
db.session.delete(user)
db.session.commit()
标签:col ssi integer object session 连接 用户 column ring
原文地址:http://www.cnblogs.com/xiepingjian/p/7856018.html