简体   繁体   中英

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).

自我注意:确保memcached正在运行。

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM