[FIXED] AttributeError: 'LoginForm' object has no attribute 'validate_on_sumbit'


I have done a registration and login page registration page works fine but login page when i Click on create account i get object has no attribute.


from flask_wtf import FlaskForm
from wtforms import StringField,PasswordField,SubmitField
from wtforms.validators import Length,EqualTo,InputRequired,ValidationError
from models import User
@app.route('/login', methods=['GET', 'POST'])

def login():
    login_form = LoginForm()
    if login_form.validate_on_sumbit():
        return "Logged in, finally!"
    return render_template('login.html', form=login_form)
class LoginForm(FlaskForm):
    """Login Form """

    username = StringField('username_label',validators=[InputRequired(message="username required")])
    password = PasswordField('password_label',validators=[InputRequired(message="Password required"),invalid_credentials])
    submit   = SubmitField('Login')


{% from 'form_helper.html' import DisplayField %}

{% extends "prelogin-layout.html" %}

{% block title %} Registration {% endblock %}

{% block content %}

    <h3>Create your account</h3>
    <form action="{{ url_for('index') }}", method="POST" >
       {{DisplayField(form.username, 'Username', autocomplete='off',autofocus=true)}}
       {{DisplayField(form.password, 'Password')}}
       {{DisplayField(form.confirm, 'Confirm Password')}}
        <div class="form-group">
            <input type="submit" value="Create" >
{% endblock %}


in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "C:\Users\Catalyst\Desktop\Python\chatAp\application.py", line 18, in login
    if login_form.validate_on_sumbit():
AttributeError: 'LoginForm' object has no attribute 'validate_on_sumbit'

I’m new at flask can you direct e where I’m mistaken
PS I’m working with flaskwtf V1.0.1


Change the line that adds submit in login.html from

        <div class="form-group">
            <input type="submit" value="Create" >


        <div class="form-group">
            {{DisplayField(form.submit, 'Create')}}

If you are using Flask WTF all fields in the form must come from the library.

I don’t know where you got the confirm variable to check the password from.
It may not work for you either. If you want the user to enter the password twice, read here: wtforms.validators.EqualTo

Answered By – Kamil Pietrzak

Answer Checked By – Terry (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published