简体   繁体   English

Python - Flask不存储会话

[英]Python - Flask not storing session

I have a Python project built using the Flask framework. 我有一个使用Flask框架构建的Python项目。

The project is established and I have installed and ran it on numerous machines (Ubuntu and OSX) using virtualenv. 该项目已经建立,我已经使用virtualenv在许多机器(Ubuntu和OSX)上安装和运行它。

I went to set up my project on a new computer with Yosemite installed. 我在安装了Yosemite的新计算机上设置了我的项目。 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). 问题是Flask会话总是一个空的dict(会话中没有任何东西)。

自我注意:确保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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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