代码之家  ›  专栏  ›  技术社区  ›  LXG

同性恋:会话问题

  •  1
  • LXG  · 技术社区  · 15 年前

    我正在用谷歌应用引擎,django 1.1(没有django-pacth或其他),编程一个应用程序,正如你所知,使用django登录和会话功能是不可能的,所以我下载 GAE实用程序和使用会话对象( http://gaeutilities.appspot.com/ )但有时这个对象会创建2个会话而不是1个会话…这里的代码

    def index(request):
    
         aSWrap = SWrap(SWrap.createSession())
         ....
          def login(request):
    
         aSWrap = SWrap(SWrap.createSession())
         ....
    
    
          class SWrap(object):
    
       @classmethod    
       def createSession():
    
         return Session(cookie_name='my_cookie',session_expire_time=7200)
    

    而设置会话没有过期或真正长的过期… enter code here 谢谢

    3 回复  |  直到 14 年前
        1
  •  3
  •   David Underhill    15 年前

    我建议使用不同的会话库。退房 this comparison of the available sessions libraries for GAE .

    我建议 gae-sessions -它提供了一个与您当前使用的库几乎相同的API,但是它的速度要快得多,不应该像上面遇到的错误那样让您头疼。

    免责声明:我写了GAE会议,但我不是唯一一个推荐它的人。这里是一个 recent thread discussing sessions 关于gae python的google组。

        2
  •  4
  •   Joe Bowman    14 年前

    根据代码判断,您在同一请求中调用了两次CreateSession。这也会引起大卫图书馆的问题。

    此外,gaeutilties会话还包含一个配置文件,您可以在该文件中根据需要修改所有默认值。

    https://github.com/joerussbowman/gaeutilities/blob/master/appengine_utilities/settings_default.py

    gaeutilies会话还具有gae会话中缺少的安全功能。恐怕大卫没有试图回答你的问题,只是建议你使用他的库,在你当前的实现中,这个库会有完全相同的问题。无论您使用的是什么会话库,您都需要确保每个HTTP请求只启动一次会话。

    为了解决这个问题并提供更好的性能,我将把gaeutilies会话转移到一个修饰程序。您可以查看GitHub上的主分支以获取更新。 https://github.com/joerussbowman/gaeutilities

        3
  •  0
  •   cope360    15 年前

    你想做什么? SWrap(SWrap.createSession()) ?它看起来像是 SWrap.createSession() 传递给 SWrap() 构造函数。你是否遗漏了 SWrap ?

    也许这更像是你想要的:

    def index(request):
        mysession = SWrap.createSession()
        ....
    
    def login(request):
        mysession = SWrap.createSession()
        ....
    
    class SWrap(object):
        @staticmethod    
        def createSession():
            return Session(cookie_name='my_cookie',session_expire_time=7200)