Let's have a page with a registration form on it. It's in section #registration
. If user submits invalid data, the page should return him back to the #registration
section and display to which fields were submitted invalid values.
I tried to render template and make response and redirect to it but I'm getting a TypeError
:
File ".../app/routes.py", line 28, in index
return redirect(url_for('.index', form=form, _anchor='registration'), 302, response)
File ".../python3.7/site-packages/werkzeug/utils.py", line 507, in redirect
mimetype="text/html",
TypeError: __call__() got an unexpected keyword argument 'mimetype'
The function looks like this:
@app.route('/', methods=['GET', 'POST'])
def index():
form = RegisterForm()
if form.validate_on_submit():
# everithing OK
return redirect(url_for('.index', _anchor='registration'))
# If form was submitted but contained invalid information
if form.is_submitted():
response = make_response(render_template('index.html', form=form))
return redirect(url_for('.index', _anchor='registration'), 302, response)
return render_template('index.html', form=form)
form
object) – Collegium