• 1000 Я следил за этим видео на YouTube
https://www.youtube.com/watch?v=vVx1737auSE, но когда я вхожу на сайт, навигация не меняется.
Навигация:
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
{% if session.user %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('recipes')}}"> Recipes</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('add_recipe') }}" >Add Recipe</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('logout') }}" >Logout</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{{url_for('login')}}">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{url_for('register')}}">Register</a>
</li>
{% endif %}
</li>
</ul>
app.py
from flask import Flask, render_template, url_for, session, redirect, request, flash
import bcrypt
@app.route("/login", methods=["GET", "POST"])
def login():
if request.method == 'POST':
users = mongo.db.users
login_user = users.find_one({'name' : request.form['username']})
if login_user:
if bcrypt.hashpw(request.form['password'].encode('utf-8'), login_user['password']) == login_user['password']:
session['username'] = request.form['username']
flash('You have been successfully logged in!')
return redirect(url_for('index'))
return 'Invalide username/password combination'
return render_template('pages/login.html')