In my project, I have a root template called base.html, which all other 
templates extend.

I'd like to create a simple navigation with user information, which I 
want to write once and put in the base template to be shown on every page.

I'm not sure what the best way of retrieving information from User 
object at the template root level is. I've read about RequestContext 
object and template processors, but the docs are not very clear to me 
and leave a lot to be guessed. I've followed the guides, but still I 
can't get User object in my template. But then again, perhaps the 
solution is simple, and I'm just too dense to see it.

Below is the very simple view code I'm testing:

from django.template import RequestContext, loader
from django.http import HttpResponse
from myproject.apps.journal.models import Post


def main(request):
     posts = Post.objects.filter(is_approved = 
True).order_by('-time_added')[:5]
     t = loader.get_template('homepage.html')
     c = RequestContext({
         'latest_posts': posts,
     })
     return HttpResponse(t.render(c))


And here's a piece of template from "homepage.html":

{% block user_nav %}
<ul id="meta-nav">
{% if user %}
        <li><a href="/community/member/{{ user.username }}/">{{ user.first_name 
}}</a></li>
{% else %}
        <li>Anonymous</li>
{% endif %}
</ul>
{% endblock %}


What am I doing wrong?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to