views:

62

answers:

2

Hi:) I have got a small problem with template double extends system. I have got a scheme:

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

When I log in to the site I have got access to all invisible blocks (invisible blocks for anonymous users) like:

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

So "blabla" is visible for me, because I am a superuser and I'm logged in. It works fine in base.html, index.html but it doesn't work in something.html. Why?? Simple it looks like user: 'superuser' is log out.

+1  A: 

Are you passing the request context to render_to_response (or HttpResponse)?
Information about logged in user must be stored in the context (see documentation), and you have to do it explicitly. Generic views automatically do it, but if you are using your own view for something.html, with a direct call to render_to_response, then you do not have information about the user.

Therefore, the code in the view should look something like:

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))
Roberto Liffredo
A: 

Yes, that is it! I use my own view, and I missed the context_instance. Great thanks :d

nykon