我正在使用this烧瓶代码。到现在为止一切正常,但是如果我想注销呢。我想在我的html代码上有一个按钮,当我注销时再次请求授权。
我如何实现这个代码def check_auth(username, password):
"""This function is called to check if a username /
password combination is valid.
"""
return username == 'admin' and password == 'secret'
def authenticate():
"""Sends a 401 response that enables basic auth"""
return Response(
'Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
@app.route("/")
@requires_auth
def index():
return render_template("welcome.html", uptime=GetUptime())
#Logout function
@app.route('/logout')
def logout():
#return redirect(url_for('index'))
flash('You were logged out')
return authenticate()))