我正在尝试将函数重定向到她自己,但是更改了参数的值。
这是我的代码:
@app.route('/', methods=["GET", "POST"])
def index(save=False):
form = FormFields()
if form.validate_on_submit:
csv = Csv(form)
csv.savecsv()
return redirect(url_for('index', save=True))
else:
print(form.errors)
return render_template('form.html', form=form, save=save)
我希望重定向时,save变量为True,但始终为False。
在表单代码中,我有这个:
{% if save %}
<script type="text/javascript"> alert("Saved!");</script>
{% endif %}
我更改了:
return redirect(url_for('index', save=True))
为此]
return render_template('form.html', form=form, save=True)
它将制作新的渲染图并且我在form.html代码中添加了它
$(document).ready(function() { $('input').val(""); });
这解决了我的问题,原因是我收到确认消息(当保存为True时,并且清除了字段]但是如果有人真的需要
return redirect url_for
可以毫无问题地使用Suman Niroula的解决方案