Давайте создадим страницу с регистрационной формой.Это в разделе #registration
.Если пользователь отправляет недействительные данные, страница должна вернуть его обратно в раздел #registration
и отобразить, в какие поля были переданы недопустимые значения.
Я попытался отобразить шаблон и сделать ответ и перенаправить на него, но яполучение 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'
Функция выглядит следующим образом:
@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)