对于我的网站授权,我使用https://flask-httpauth.readthedocs.io/en/latest/。现在我试图让它使用数据库中的数据。为此,我创建了名为Users的数据库并创建了名为username和password的列。HTTPBasicAuth的查询信息
@staticmethod
def get_user():
query = (Users
.select())
user = []
for s in query:
user.append(s)
return user
(我不知道这是否是正确的)
下一页我:
要定义它的类为模型我做了GET_USER功能,这看起来像它后获得从该表数据不得不修改get_pw功能,但我还不能确定如何修改它,我把它看起来就像是:
@auth.get_password
def get_pw(username):
if username in Users.get_user():
return users.get(Users.get_user())
return None
现在运行的网站后,我得到及时给予登录名和密码,但这些我在数据库中设置的功能似乎不起作用,所以get_pw函数一定有问题。另外我使用peewee sql来管理数据库:http://docs.peewee-orm.com/en/latest/peewee/querying.html