I am using flask and wtforms. When a user clicks a submit button for the form, I want to pop up a message saying that the submission succeeded. For that I have a parameter for my flask route with a default value of False. When the user submits, I want it to be true, so when it re-renders the page, it knows to show the user the extra bit saying "Success". However the parameter always seems to be false. My python looks like,
@app.route('/myPage', methods=['GET', 'POST'])
def myPage(success=False):
print success
form = MyForm()
if form.validate_on_submit():
print "did validate"
return redirect(url_for('myPage', success=True))
return render_template('/MyPage.html', form=form, success=success)
And my html looks like,
...
{% if success %}
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> User added
</div>
{% endif %}
...
<form method="POST" action="{{ url_for('register', success=True) }}">
...
In both my python and html redirects, I try setting success to be true, but no combination of those seem to work. When I "print success", it always says that it is false. Any ideas?