Перенаправление колбы не перенаправляет на новую страницу. В моей функции индекса при входе в систему редирект не перенаправляет на домашнюю страницу пользователя; однако после обновления страницы и проверки current_user.authenticated он перенаправляется на домашнюю страницу пользователя. У меня одинаковый точный код перенаправления в обоих операторах if. Почему он не перенаправляет сразу после входа в систему пользователя?
@login.user_loader
def load_user(user_id):
user = User()
username = user.get_username(str(user_id))
user = User(username = username, id = user_id)
return user
@app.route("/", methods=['GET', 'POST'])
def index():
if current_user.is_authenticated:
print('this redirect works')
return redirect(url_for('home', username = str(current_user.username)))
else:
username = str(request.form.get('user'))
password = str(request.form.get('password'))
user = User(username = username)
my_hash = user.get_password(username)
if user.check_password(my_hash, password):
my_id = user.get_user_id(username)
user = User(username = username, id = my_id)
login_user(user, remember=True)
print('this redirect doesnt work')
return redirect(url_for('home', username = str(current_user.username)))
return render_template('index.html')
@app.route("/<username>", methods=['GET', 'POST'])
@login_required
def home(username):
print('here')
if (str(request.form.get('signout')) == 'true'):
print('logout')
logout_user()
return redirect(url_for('index'))
return render_template('home.html')
Вот консоль при входе пользователя 'a'
Serving Flask app "models" (lazy loading)
Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
Debug mode: off
Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
127.0.0.1 - - [20/Nov/2018 10:11:45] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [20/Nov/2018 10:11:45] "GET /static/css/style.css HTTP/1.1" 200 -
127.0.0.1 - - [20/Nov/2018 10:11:45] "GET /static/scripts/jsx/signin.bundle.js HTTP/1.1" 200 -
127.0.0.1 - - [20/Nov/2018 10:11:46] "GET /favicon.ico HTTP/1.1" 401 -
this redirect doesnt work
127.0.0.1 - - [20/Nov/2018 10:11:49] "POST / HTTP/1.1" 302 -
here
127.0.0.1 - - [20/Nov/2018 10:11:50] "GET /a HTTP/1.1" 200 -