flask_sqlalchemy对象在使用flask_security时没有添加属性 [英] flask_sqlalchemy object does not have attribute add when using flask_security

查看:159
本文介绍了flask_sqlalchemy对象在使用flask_security时没有添加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用flask_security添加一些角色/用户,但是在尝试使用SQLAlchemySessionUserDatastore创建用户时遇到了此问题.因此,我首先从创建user_datastore开始,如指南

I am trying to add some roles/users with flask_security but run into this issue when I try to create users with the SQLAlchemySessionUserDatastore. So I first start by creating user_datastore like the guide

db = SQLAlchemy(app)
user_datastore = SQLAlchemySessionUserDatastore(db, User, Role)
security = Security(app, user_datastore)
user_datastore.create_user(email='test', password='passowrd')

这是我偏离指南的地方,尝试创建一个测试用户.似乎是db = SQLAlchemy(app)导致了我的问题.

this is where I deviate from the guide and try to just create a test user. Looks like the db = SQLAlchemy(app) is causing me issues.

    self.db.session.add(model)
AttributeError: 'SQLAlchemy' object has no attribute 'add'

推荐答案

user_datastore = SQLAlchemySessionUserDatastore(db,User,Role)

user_datastore = SQLAlchemySessionUserDatastore(db, User, Role)

上面这行可能是罪魁祸首.

The above line may be the culprit here.

我的解决方法如下: user_datastore = SQLAlchemySessionUserDatastore( db.session ,用户,角色)

My resolution is below: user_datastore = SQLAlchemySessionUserDatastore(db.session, User, Role)

这篇关于flask_sqlalchemy对象在使用flask_security时没有添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆