У меня проблема с методом form.validate_on_submit () из wtforms
, он выдает следующую ошибку каждый раз, когда я отправляю форму:
'LoginForm' object has no attribute 'validate_on_submit'
forms.py:
from wtforms import Form, validators, StringField, PasswordField
class LoginForm(Form):
email = StringField('Email Address', [validators.DataRequired(message='Field required')])
password = PasswordField('Password', [validators.DataRequired(message='Field required')])
rout.py
from flask import Flask, escape, request, render_template, redirect, url_for
from securepi import app, tools
from securepi.forms import LoginForm
@app.route('/login/', methods=['GET', 'POST'])
def login():
error = None
try:
form = LoginForm(request.form)
if request.method == "POST" and form.validate_on_submit():
email = str(form.email.data)
password = tools.encrypt(str(form.password.data))
print("email: {}, password: {}".format(email, password))
# if valid account create session and redirect to index
return redirect(url_for('index'))
else:
print("FAIL")
error = "Invalid username or password"
except Exception as e:
return(str(e))
return render_template('login.html', form = form)
и форма
<form action="" method="post">
<div class="form-group has-feedback">
<input type="email" name="email" class="form-control" placeholder="Email" value="{{ request.form.email }}">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" name="password" class="form-control" placeholder="Password" value="{{ request.form.password }}">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<!-- /.col -->
<div class="col-xs-12">
<button type="submit" class="btn btn-primary btn-block">Log in</button>
</div>
<!-- /.col -->
</div>
</form>