It is necessary to change the value of the login_status variable in the base template that is used for all pages of the application, using python, jinja2. The variable also has a default value of "Input." If the login is successful, login_status becomes "Logout", if not - "Login". But correctly changing the variable occurs only on one page of the personal account, and on all other pages the default value continues to be used.
How to fix this situation?
base.html:
<li class="in">{{login_status | default('Вход')}}</li> <form name="form_in" method = 'post' action = '/personal_account'> <input type="text" placeholder="Логин" id="log" name="login"/> <input type="password" placeholder="Пароль" id="pass" name="password"/> <input type="submit"/> </form> Python function:
@app.route('/personal_account', methods=['POST']) def welcome(): login = request.form['login'] password = request.form['password'] login_status = u'Выйти' sidebar_login_status = 'out' if not validate_user(login, password): login_status = u'Войти' sidebar_login_status = 'in' return u'Неправильный логин!', login_status, sidebar_login_status # добавлено после Edit One user = User() user.id = login login_user(user) # ....... data = get_user_data(login) return render_template('private.html', data=data, login_status=login_status, sidebar_login_status=sidebar_login_status) EDIT ONE
To save user "login", the Flask-Login module is used. The User () class is used as it is by default.
The problem is that the user remains logged in for the entire session, and I need to change the value of the login_status variable in the base html template in this case.
current_user.is_authenticatedin the template instead of using the variablelogin_status? - Sergey Gornostaevcurrent_user.is_authenticated, then use this value thatlogin_statuswish to set. - jfs