Flask session variable not persisting between requests
<p>Using the app below and Flask 0.11.1, I navigated to the routes associated with the following function calls, with the given results: </p>

<ul>
<li>create():    '1,2,3'  # OK</li>
<li>remove(1) : '2,3'    # OK</li>
<li>remove(2) : '1,3'    # expected '3'</li>
<li>maintain():  '1,2,3'  # expected '1,3' or '3'</li>
</ul>

<p>&nbsp;</p>

<pre><code>from flask import Flask, session

app = Flask(__name__)

@app.route('/')
def create():
    session['list'] = ['1','2','3']
    return ",".join(session['list'])

@app.route('/m')
def maintain():
    return ",".join(session['list'])

@app.route('/r/&lt;int:id&gt;')
def remove(id):
    session['list'].remove(str(id))
    return ",".join(session['list'])

if __name__ == '__main__':
    app.secret_key = "123"
    app.run()
</code></pre>

<p>This question is similar in theme to <a href="http://stackoverflow.com/questions/18139910/using-session-in-flask-app">this question</a>, <a href="http://stackoverflow.com/questions/18709213/flask-session-not-persisting">this</a>, and <a href="http://stackoverflow.com/questions/7100315/flask-session-member-not-persisting-across-requests">this one</a>, but I'm setting the secret key and not regenerating it, and my variable is certainly not larger than the 4096 bytes allowed for cookies. Perhaps I'm missing some more basic understanding about Flask session variables?</p>

<p>From <a href="http://flask.pocoo.org/docs/0.11/api/#flask.session.modified" rel="nofollow">the doc</a>:</p>

<blockquote>
  <p>Be advised that modifications on mutable structures are not picked up automatically, in that situation you have to explicitly set the [<code>modified</code> attribute] to <code>True</code> yourself. </p>
</blockquote>

<p>Try:</p>

<pre><code>session['list'].remove(str(id))
session.modified = True
</code></pre>

python session flask