Pyramid Cup Receiving Sessions Created

I am trying to use a pyramid glass in a Pyramid structure and it just doesnโ€™t work, it creates session objects, but I cannot access them using the line

@view_config(route_name='load_qli', renderer='json') def load_qli(request): request.environ['beaker.session'] 

It gives the following error:

 KeyError KeyError: 'beaker.session' 

My development.ini file is as follows

 # 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 

and init.py like this

 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 ) 

I create a session as follows

 def my_view(request): session = request.session session['name'] = 'Fred Smith' session.save() 

Where am I mistaken?

+4
source share
1 answer

You should simply use the include method, and the pyramid_beaker package can initialize itself from ini values.

in your ini file:

 pyramid_includes = pyramid_beaker 

or inside your main function __init__.py file:

 config.include('pyramid_beaker') 

You can read here http://docs.pylonsproject.org/projects/pyramid_beaker/en/latest/#setup

The usual way to access a session is to query, as you do in my_view:

 session = request.session 

The pyramid_beaker package uses the factory pyramid session, and the session control method is not through the request.environement ['beaker.session'] object, for example, beaker. For more information read http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/sessions.html

+5
source

Source: https://habr.com/ru/post/1391418/


All Articles