1

我是金字塔框架的初学者。我试图在应用程序中启动一个会话,但会话不起作用。这是以下代码:init.py

from pyramid.config import Configurator    
from pyramid.session import SignedCookieSessionFactory
def main(global_config, **settings):
    my_session_factory = SignedCookieSessionFactory('itsaseekreet')
    config = Configurator(settings=settings)     
    config.set_session_factory(my_session_factory)
    config.add_route('next', '/next')

视图.py

@view_config(route_name="next")
def next(request):
try:            
    query=request.dbsession.query(UserMaster)
    global user_id,password
    user_id=request.params['uname']
    password=request.params['password']
    session=request.session
    session['username']=user_id
    two=query.filter(UserMaster.user_id==user_id,UserMaster.password==password).first()
    if two is None:
        print('Invaid Username or password')
        return render_to_response('../templates/login.jinja2', {}, request=request)
    else:       
           return render_to_response('../templates/menu.jinja2', {})

except DBAPIError:
    return Response(db_err_msg, content_type='text/plain', status=500)

@view_config(route_name='index')
def index(request):
try:
    name = request.session.get('username')
    return render_to_response('../templates/index.jinja2', {'name':name},   request=request)
except DBAPIError:
    return Response(db_err_msg, content_type='text/plain', status=500)

@view_config(route_name='logout', renderer='../templates/login.jinja2')
def logout(request):
try:
    request.session().invalidate()
except DBAPIError:
    return Response(db_err_msg, content_type='text/plain', status=500)

我得到 TypeError: 'CookieSession' 对象不可调用

4

0 回答 0