Using session in flask app
Question: I'm sure there is something that I'm clearly not understanding about session
in Flask but I want to save an ID between requests. I haven't been able to get
session to work so I tried a simple Flask app below and when I load it I get
an internal server error

    
    
    #!/usr/bin/env python
    
    from flask import Flask, session
    
    app = Flask(__name__)
    
    @app.route('/')
    def run():
        session['tmp'] = 43
        return '43'
    
    if __name__ == '__main__':
        app.run()
    

Why can't I use store that value in session?


Answer: According to [Flask sessions
documentation](http://flask.pocoo.org/docs/quickstart/#sessions):

> ... What this means is that the user could look at the contents of your
> cookie but not modify it, unless they know the secret key used for signing.
>
> In order to use sessions you **have to set a secret key**.

Set _secret key_. And you should return string, not int.

    
    
    #!/usr/bin/env python
    
    from flask import Flask, session
    
    app = Flask(__name__)
    
    @app.route('/')
    def run():
        session['tmp'] = 43
        return '43'
    
    if __name__ == '__main__':
        app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
        app.run()
    

