Post/Redirect/Get pattern in flask
<p>The view function of my toy app was:</p>

<pre><code>@app.route('/', methods=['GET', 'POST'])
def index():
    name = None
    form = NameForm()
    if form.validate_on_submit():
        name = form.name.data
        form.name.data = ''
    return render_template('index.html', form=form, name=name)
</code></pre>

<p>And it looks like this when I use PRG:</p>

<pre><code>@app.route('/', methods=['GET', 'POST'])
def index():
    form = NameForm()
    if form.validate_on_submit():
        session['name'] = form.name.data
        return redirect(url_for('index'))
    return render_template('index.html', form=form, name=session.get('name'))
</code></pre>

<p>As you can see, the <code>form.name.data = ''</code> line is used to clear the input field in the first version, but it's not needed in the second version. I thought Flask-WTF would automatically pass the text in <code>StringField</code> into the new <code>form</code> instance, but for some reasons, it didn't.</p>

<p>My question is: Why <code>form.name.data</code> is no longer available between different requests when I use PRG?</p>

<p>It can't pass anything on a redirect, as it is a completely new request.</p>

python redirect flask flask-wtforms post-redirect-get