user4425526
user4425526

Reputation:

Python - Flask not storing session

I have a Python project built using the Flask framework.

The project is established and I have installed and ran it on numerous machines (Ubuntu and OSX) using virtualenv.

I went to set up my project on a new computer with Yosemite installed. It installed all of the requirements with no errors and the site runs locally without errors.

The problem is that the Flask session is always an empty dict (nothing is ever in the session).

Upvotes: 1

Views: 1003

Answers (2)

user4425526
user4425526

Reputation:

Note to self: make sure memcached is running.

Upvotes: 2

Michael
Michael

Reputation: 1197

Create a new route with the following code in the view function:

if 'logged' in session:
    return True
return False

Then you can add a unit test:

def test_no_session(self):
   response = self.app.get('/test')
   self.assertEqual(False, response.data)

def test_session(self):
    with self.app:
        with self.app.session_transaction() as session:
            session['logged'] = True
        response = self.app.get('/test')
    self.assertEqual(True, response.data)

Upvotes: 1

Related Questions