Python 3.x 如何在Python瓶子中注销?

Python 3.x 如何在Python瓶子中注销?,python-3.x,bottle,Python 3.x,Bottle,我有以下测试片段: def check(username, password): if username == "b" and password == "password": return True return False @route('/logout') @route('/logout', method="POST") def logout(): # template with a logout button # this does redirect su

我有以下测试片段:

def check(username, password):
    if username == "b" and password == "password":
        return True
    return False

@route('/logout')
@route('/logout', method="POST")
def logout():
# template with a logout button
# this does redirect successfully, but this shouldn't happen 
    redirect('/after-login')


@route('/after-login')
@auth_basic(check)
def after_login():
    return "hello"

@route('/login')
@route('/login', method="POST")
def login():
    return template("views/login/login_page")
    username = post_get('username')
    password = post_get('password')

我正在尝试注销系统,但我无法找到任何有关如何注销的资源。基本上,我尝试了dir(response)和dir(request),但没有找到任何似乎可以关闭会话的函数(主要是尝试重置cookies),除非我关闭浏览器。

也出现了同样的问题。嗯,我在文档中找到并使用的决策是
response.delete\u cookie(“”)

因此,每次我进入设置任何cookie的页面时,首先我会删除所有可能更改cookie的内容。

您想注销HTTP Basic Auth,这并不是它的设计初衷。但是有:返回一个HTTP401

from bottle import abort

@route('/logout', method=["GET", "POST"])
def logout():
    abort(401, "You're no longer logged in")

这行吗?

顺便说一句,您可以将您的
@route
呼叫合并为一个
@route('/login',method=['GET',POST'])
在这种情况下不起作用。OP的代码使用基本身份验证,而不是cookies。无论如何,它不适合我所描述的。每次我以这种方式删除所有cookie时,所有set_cookie都不再适用于特定路线的每种方法。所以唯一有效的方法就是删除所有没有重新设置的cookies