# Add user logouts to the portfolio project

Handling user logouts is very straightforward: clear the session, and the user will be logged out!

The session variable has a .clear() method you can call which will do this for you!

In routes.py:

def logout():
    current_theme = session.get("theme")
    session["theme"] = current_theme

    return redirect(url_for(".login"))

An alternative, if you wanted to keep some data in the session but remove other data, could be to do this:

del session["user_id"]
del session["email"]

With that, we can include a link in the nav bar to the logout endpoint:

-    href="#"
+    href="{{ url_for('pages.logout') }}"
     <span class="nav__item">Log out</span>