4
我試圖用金字塔燒杯在金字塔框架,它只是沒有工作,那麼創建會話對象,但我不能用線金字塔燒杯訪問會話已創建
@view_config(route_name='load_qli', renderer='json')
def load_qli(request):
request.environ['beaker.session']
訪問它們它提供了以下錯誤
KeyError
KeyError: 'beaker.session'
我development.ini文件看起來像這樣
# pyramid_beaker settings
session.type = file
session.data_dir = %(here)s/data/sessions/data
session.lock_dir = %(here)s/data/sessions/lock
session.key = customerskey
session.secret = customerssecret
session.cookie_on_exception = true
和init.py這樣
from pyramid.config import Configurator
from sqlalchemy import engine_from_config
from qlipe.models import DBSession
from pyramid_mailer import mailer_factory_from_settings
from pyramid_beaker import session_factory_from_settings
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
# pyramid_beaker add-on
session_factory = session_factory_from_settings(settings)
config = Configurator(
settings=settings,
session_factory=session_factory
)
我創建這樣
def my_view(request):
session = request.session
session['name'] = 'Fred Smith'
session.save()
會話我在哪裏去了?
我不熟悉金字塔;你不能只在第一個代碼示例中執行'request.session'?傳遞給'my_view'的請求和傳遞給'load_qli'的請求有什麼不同? – AdamKG