I am unable to figure out why my form will not validate. I have made sure that the CSRF field is inserted in to the HTML with form.hidden_tag
Here is the code for my registration form:
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField
from wtforms.validators import DataRequired, Length, Email, EqualTo
class RegistrationForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=2, max=20)])
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo(password)])
submit = SubmitField('Register')
Here is the function in which I am checking to see if the form is validated. It does submit, as the program prints out 'submitted' into my terminal
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegistrationForm()
if form.is_submitted():
print("submitted")
if form.validate_on_submit():
flash(f'Account created for {form.username.data}!', 'success')
return redirect(url_for('home'))
print(forms.errors)
return render_template('register.html', title='Register', form=form)
Using forms.errors, I get the following error message:
{'confirm_password': ["Invalid field name '<UnboundField(PasswordField, ('Password',), {'validators': [<wtforms.validators.DataRequired object at 0x00000205913D2F28>]})>'."]}
I am unsure of what this means.
If it helps, I have all my current code located on GitHub: https://github.com/tomajohnson21/FakeBook