flask


  • url_for(‘home’) : Here home is actually the view method name.
  • use flash() for showing one time messages. First argument is the the actual message that you want to show. flash() accepts a second argument called category. This is commonly used to pass in bootstrap class for flash message. I commonly use ‘success’ or ‘danger’ bootstrap classes.

    In your python view:

    Then we display these flash messages in a template file like so:

    Here with_categories=true part allows the flashed messages to accept bootstrap classes like ‘success’ that we passed.

  • username = StringField('Username', validators=[DataRequired(), Length(min=2, max=20)]) here ‘Username’ is automatically designated as label for this form field in the form. So in my html for the corresponding form, I can set both label and actual form like so:

  • How to display validation errors on form fields

    We display form fields like so:

    Now, if the user entered and email that was not valid, we need to show some feedback message to the user (we call it postback). We do it by using “is-valid” class offered by Bootstrap like so.

    Here, the else block shows the form field when there was no error.