2009-12-29 64 views
0

嗨:)我有一个模板双扩展系统的小问题。我有一个计划:django双“扩展”,登录问题

base.html ---> index.html ---> something.html 

当我登录到我已经喜欢了访问所有无形的块(匿名用户不可见的块)的网站:

{% if user.is_superuser %} 
    blabla 
{% endif %} 

所以“布拉布拉” 是对我来说可见的,因为我是超级用户,而且我已登录。它在base.html,index.html中正常工作,但它在something.html中的不起作用。为什么??简单看起来像用户:'超级用户'注销。

+1

不应该有两次延长任何问题。我认为你需要向我们展示你的代码以帮助我们。 – Alasdair 2009-12-29 13:30:16

回答

1

您是否将请求context传递给render_to_response(或HttpResponse)?
有关登录用户的信息必须存储在上下文中(see documentation),您必须明确地执行此操作。 通用视图会自动执行此操作,但如果您正在使用自己的视图来处理something.html,并直接调用render_to_response,那么您没有关于该用户的信息。

因此,在视图中的代码应该是这个样子:

from django.shortcuts import render_to_response 
from django.template import RequestContext 

def my_personalized_view(request): 
    return render_to_response('something.html', 
          {}, 
          context_instance=RequestContext(request))