Question: Im using [this](http://flask.pocoo.org/snippets/8/) Flask code. Its working fine till now, but what if I wanna logout. I would like to have a button on my html code, and when I logout to request auth again.
How can I impliment this code

```
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()))

```

Answer: 
You are using Basic auth. It doesn't have the concept of "log out", but, you can simulate one by sending wrong credentials (for instance a username with an invalid password) and returning `401` instead of `200`. There are multiple ways to implement a logout, but for keeping it simple you could render a template view or return an informative text, always using `401` as the response http code:

```
@ns.route('/logout')
def logout():
    """End the current user session"""
    return "Your session was closed", 401

```
You can create a session with the auth data (no matter whether use basic auth), and when you want log out simply delete the session data.