GAE Webapp2-销毁会话无效 [英] GAE Webapp2 - destroying session doesn't work

查看:100
本文介绍了GAE Webapp2-销毁会话无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还是我误会了破坏工作的方式?这是一个示例代码:

Or do I misunderstand how destroying work? Here's an example code:

class TestHandler(BaseHandler):
    def get(self):
        counter = self.session.get('counter')
        if not counter:
            counter = 0
        counter += 1

        if counter > 5:
            self.auth.unset_session()
        else:
            self.session['counter'] = counter

        return self.response.write ( counter )

会话有效,计数器计数,但是会话没有被销毁或者销毁它不会使值无效?

Session works, the counter counts, but either session isn't destroyed or destroying it doesn't null the value?

仅销毁某些值(如userid和sessionid)还是我会完全忽略这一点吗?谢谢.

Does destroying null only some values like userid and sessionid or do I completely miss the point? Thanks.

推荐答案

unset_session从会话中删除 user ,而不是其他会话变量. unset_session方法位于auth模块上.

unset_session removes the user from the session not the other session variables. The unset_session method is on the auth module.

如果您对代码进行更深入的了解,可以看看代码在做什么. http://code.google.com/p/webapp -improved/source/browse/webapp2_extras/auth.py

If you dig a little deeper in the code you can have a look at what the code is doing. http://code.google.com/p/webapp-improved/source/browse/webapp2_extras/auth.py

 def unset_session(self):
        """Removes a user from the session and invalidates the auth token."""
        self._user = None
        data = self.get_session_data(pop=True)
        ....

如果您尝试取消设置计数器,则可以通过调用self.session.pop('counter')

If you were trying to unset the counter, you could pop the session variable by calling self.session.pop('counter')

例如:

   counter = self.session.get('counter')
    if not counter:
        counter = 0
    counter += 1

    if counter > 5:
        self.session.pop('counter')
    else:
        self.session['counter'] = counter

    return self.response.write ( counter )

如果您想清除会话中的所有内容,可以调用self.session.clear()

If you want to clear everything from the session, you can call self.session.clear()

这篇关于GAE Webapp2-销毁会话无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆