from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired, Email


class Login(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])

from flask import flash
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField
from wtforms.validators import DataRequired, Email, Length


def flash_errors(form):
    """ Universal interface to handle form error.
    Handles form error with the help of flash message
    """
    for field, errors in form.errors.items():
        for error in errors:
            flash(u'Error in the %s field - %s' % (
                getattr(form, field).label.text,
                error
            ))


class Login(FlaskForm):
    username = StringField('Username',
                           validators=[DataRequired(), Length(max=16)])
    password = PasswordField('Password',
                             validators=[DataRequired()])

Add universal interface for validation error message
Add universal interface for validation error message
