views.py
@blueprint.route('/formularhodnota', methods=['GET', 'POST'])
def formularhodnotanew():
form = FormularHodnota()
if form.validate_on_submit():
return form.hodnota1.data + form.hodnota2.data
return render_template("public/formularhodnota.tmpl", form=form)
forms.py – validace
class FormularHodnota(Form):
hodnota1 = TextField('Hodnota1', validators=[
Predicate(safe_characters, message="Please use only letters (a-z) and numbers"),
Length(min=3, max=20, message="Please use between 3 and 30 characters"),
InputRequired(message="You can't leave this empty")
])
hodnota2 = TextField('Hodnota2', validators=[
Predicate(safe_characters, message="Please use only letters (a-z) and numbers"),
Length(min=3, max=30, message="Please use between 3 and 30 characters"),
InputRequired(message="You can't leave this empty")
])
template
{% from "macros/fields.tmpl" import render_input_field, render_password_field,
render_submit %}
{% extends "shared/layout.tmpl" %}
{% block title %}Hodnota{% endblock %}
{% block content %}
<h3>hodnota</h3>
<form method="POST" id="register-form">
{{ form.hidden_tag() }}
{{ render_input_field(form.hodnota1) }}
{{ render_input_field(form.hodnota2) }}
{{ render_submit() }}
</form>
{% endblock %}