I write a site on Flask, I connected flask-security, at first I changed the authorization template to the standard flask-security authorization template, I found a way to solve this problem, but now, as soon as I add a form to my template to work with WTF- forms, the error
jinja2.exceptions.UndefinedError: 'form' is undefined appears
if I make some simple template, then everything seems to be fine, although the parameter form=form is specified in my view function. Here is my html file for this page(templates/security/login_user.html)
{% extends 'base.html' %}
{% block body %}
{{ super() }}
{% for cat, msg in get_flashed_messages(True) %}
<div class="flash {{cat}}">{{msg}}</div>
{% endfor %}
<div class="container">
<form class="box" method="POST">
{{ form.hidden_tag() }}
<h1 title="Авторизуйтесь,будь ласка">Авторизація</h1>
<div class="group">
<label>{{ form.username.label }}</label>
{{ form.username }}
</div>
<div class="group">
<label>{{ form.email.label }}</label>
{{ form.email }}
</div>
<div class="group">
<label>{{ form.password.label }}</label>
{{ form.password }}
</div>
<div class="group">
<center><button>Авторизуватися</button></center>
</div>
<a href="{{ url_for('reset_password') }}">Забули пароль?</a>
</form>
</div>
{% endblock %}
This is my view-function to this page
@app.route('/login', methods=['POST', 'GET'])
def login_page():
form = AuthorizationForm()
if form.validate_on_submit():
username = form.username.data
email = form.email.data
password = form.password.data
if username and email and password:
user = User.query.filter_by(username=username, email=email).first()
if check_password_hash(user.password, password):
login_user(user)
return redirect(url_for('index_page'))
else:
flash('Неправильний логін або пароль', category='error')
else:
flash('Заповніть,будь ласка,всі поля', category='error')
return render_template('security/login_user.html', title='Авторизація', form=form,
css_link=css_file_authorization)
This is my class to WTFForm
class AuthorizationForm(FlaskForm):
username = StringField('Введіть свій username: ')
email = StringField('Ваш email: ')
password = PasswordField('Введіть свій пароль: ')
And in the documentation, I saw that it is possible to write it here for connecting the template:
SECURITY_LOGIN_USER_TEMPLATE = '/templates/security/login_user.html'
But it doesn`t help