Your form is submitting to / when the method is routed for /template unless that is a typo, you should adjust your form's action attribute to point at the template view: action="{{ url_for('template') }}"
/
/template
action
template
action="{{ url_for('template') }}"
Replace:
<form action="/" method="post">
with:
<form action="{{ url_for('template') }}" method="post">
If you omit the action attribute, the form will post to the current URL.
<form method="post">