服务器端http会话
obsession的Python项目详细描述
快速的wsgi会话。零依赖性。Python3准备好了。
基本用法:
import obsession application = obsession.SessionMiddleware(application)
高级用法:
# Customize all the options application = obsession.SessionMiddleware( application, id_persister=obsession.CookieIdPersistence(cookie_name='mysession', max_age=86400, path='/my-site', domain='mysite.example.org' secure=True), backend=obsession.FileBackend(directory='/tmp/session-store', prefix='session_') )
您的应用程序现在将在 environ['ob.session']。
session对象的作用类似于常规字典:
session = environ['ob.session'] session['foo'] = 'bar' session['bar'] = [1, 2, 3]
每当您更改 会话对象本身-例如,通过分配新键或重新分配 现有密钥。但是,如果更改已存储的值,则 您应该调用session.save()以确保保存更改
有一些有用的额外属性和方法:
# Persist the session to the backend session.save() # What's my session id? my_session_id = session.id # Cycle the session id. # This generates a new session id and invalidates the old one. session.cycle() # Load a session with a known id. # Useful if you need to pass the session through another service that # does not have access to the cookie. s = environ['ob.session'] s.load_id('my_session_id') # Delete the session. # This removes all data from the backend storage and deletes the client's # session cookie session.delete()
0.2(发布日期:2018-03-12)
- 添加了JSON序列化程序
- 错误修复:以句点结尾的会话ID不再被自动删除
- 仅当创建新会话或ID 已更改,避免发送不必要的set cookie头。
0.1
- 初始版本