SQLAlchemy没有提交更改 - Flask

时间:2017-11-07 05:10:09

标签: python flask sqlalchemy flask-sqlalchemy flask-security

所以我基本上想做的是让用户填写一个表单,并将布尔值设置为True,告诉我他们是一个用户。我将POST请求发送到数据库时将其设置为True,但是当我查看列时,它会显示" [null]"。我不明白我做错了什么......

class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(120))
    last_name = db.Column(db.String(120))
    email = db.Column(db.String(180), unique=True)
    password = db.Column(db.String(255))
    isUser = db.Column(db.Boolean())
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role', secondary=roles_users,backref=db.backref('users', lazy='dynamic'))

@app.route('/post_user', methods=['POST'])
def post_user():
    user = User(request.form['first_name'], request.form['last_name'], request.form['email'], request.form['password'])
    user.isUser = True
    db.session.add(user)
    db.session.commit()
    return redirect(url_for('login'))

0 个答案:

没有答案