Solution 1 :

An action attribute on an li element doesn’t make sense. You can use a link as in this answer:

<li class="active"><a href="{{ url_for('logout') }}">Logout</a></li>

Your href was pointing to the index, your action is pointing to logout, and you’re rendering the login template in your Flask route, so you’d need to decide which you want: render the login template or redirect to the index after hitting logout.

Problem :

I would like to use logout list item in my navbar to use as action flask logout function. Didnt find a way either with < li> nor < a> in documentation, is it possible?

  <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="{{ url_for('home') }}">Home</a></li>
        <li class="active"><a href="{{ url_for('food') }}">New Food Item</a></li>
        <li class="active"><a href="{{ url_for('view') }}">Check date</a></li>
        <li class="active"><a href="{{ url_for('set_up') }}">Calorie setup</a></li>
        <li class="active"><a href="{{ url_for('index') }} action="/logout">Logout</a></li>
      </ul>
    </div>
@app.route("/logout", methods=["GET","POST"])
def logout():
        logout_user()
        return render_template("login.html")

Comments

Comment posted by Hedgy

couldn’t you just set it as the

By