问题是,即使数据已验证并已处理,您始终使用传递的任何数据来呈现表单。此外,浏览器会存储上一个请求的状态,因此,如果此时刷新页面,浏览器将重新提交表单。
处理成功的表单请求后,重定向到页面以获取新状态。
@app.route('/register', methods=['GET', 'POST'])def register(): form = RegistrationForm() if form.validate_on_submit(): # do stuff with valid form # then redirect to "end" the form return redirect(url_for('register')) # initial get or form didn't validate return render_template('register.html', form=form)


