简体   繁体   English

Turbogears2会话管理

[英]Turbogears2 session management

In theory i did what i'm supposed to do in order to store some data in session variables but my controllers can't reach them. 理论上,我做了我应该做的事,以便将一些数据存储在会话变量中,但是我的控制器无法访问它们。 Here's the code: 这是代码:

    @expose('')
    @require(predicates.not_anonymous())
    def savecustomer(self, customer=None, **kw):
    if customer is None:
        flash(_('Select a customer!'), 'error')
        redirect('/')
    customer = DBSession.query(Customer).filter_by(customer_id=customer).first()
    session.delete()
    session['customer'] = True
    session['customer_id'] = customer.customer_id
    session['customer_name'] = customer.customer_name
    ...
    session.save()

and here is my view code: 这是我的查看代码:

  {% if request.identity %}
      {% if session['customer'] %}
        <div class="customer"><i>{{ session['customer_name'] }}
              {% if session['customer_type'] %} {{ session['customer_type'] }} {% endif %}
              </i></div>
      {% else %}
        <div class="nocustomer">No customer selected</div>
      {% endif %}
  {% endif %}

and here's my "debugging": 这是我的“调试”:

for i in session.iterkeys():
    print i
for i in session.itervalues():
    print i
customer
customer_id
customer_name
True
3
Ciccio Pasticcio S.p.a.

and if i run the same code in another controller it gives me this: 如果我在另一个控制器中运行相同的代码,它将给出以下信息:

_id
832f62d3bc5140c4a9f3ba36bc3e876a

What am i doing wrong? 我究竟做错了什么? (this used to work until i "fixed" something else :) ) (这一直起作用,直到我“修复”了其他东西:))

我通过删除解决了错误

session.delete() 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM