标签:install back 状态 rip text 实例 auth ble 保存状态
Restful API不保存状态,无法依赖Cookie及Session来保存用户信息,自然也无法使用Flask-Login扩展来实现用户认证。所以这里,我们就要介绍另一个扩展,Flask-HTTPAuth。
pip install flask-httpauth
接下来创建扩展对象实例:
from flask import Flask from flask_httpauth import HTTPBasicAuth app = Flask(__name__) auth = HTTPBasicAuth()
注意,初始化实例时不需要传入app对象,也不需要调用”auth.init_app(app)”注入应用对象。另外,Flask-HTTPAuth提供了几种不同的Auth方法,比如HTTPBasicAuth,HTTPTokenAuth,MultiAuth和HTTPDigestAuth。上例中我们使用了HTTPBasicAuth,下文中也会分别介绍HTTPTokenAuth和MultiAuth
用户名及密码验证
1
2
3
4
5
|
fromflask importFlask
fromflask_httpauth importHTTPBasicAuth
app=Flask(__name__)
auth=HTTPBasicAuth()
|
标签:install back 状态 rip text 实例 auth ble 保存状态
原文地址:http://www.cnblogs.com/Erick-L/p/7060806.html