form with flask code example

Example 1: flask form options

{% macro render_field(field) %}
  <dt>{{ field.label }}
  <dd>{{ field(**kwargs)|safe }}
  {% if field.errors %}
    <ul class=errors>
    {% for error in field.errors %}
      <li>{{ error }}</li>
    {% endfor %}
    </ul>
  {% endif %}
  </dd>
{% endmacro %}

Example 2: flask form

class PostForm(FlaskForm): 
    title = StringField('Title', validators=[DataRequired()]) 
    content = TextAreaField('Content', validators=[DataRequired()]) 
                      validators=[DataRequired(), Length(min=2, max=50)])
    submit = SubmitField('Post')