On Tue, Jun 24, 2008 at 15:47, Huuuze <[EMAIL PROTECTED]> wrote:
>
> A n00b question for everyone: My base template has a "Welcome
> <username>" section in it.  Currently, I'm adding the username (which
> is coming from Django's auth/auth framework) to the template with the
> following bit of code:
>
> <p>{{ request.session.user.username }}</p>
>
> This works, however, it requires me to add the "request" object to any
> return statement that deals with displaying a page:
>
> return render_to_response('somepage.html', {'request':request})
>
> I'm guessing there's a better way to do this, but I can't seem to find
> an answer.  Help!

I believe you can use django.template.RequestContext to accomplish
what you want; in your view, do something like:

from django.template import RequestContext

<snip>

return render_to_response('somepage.html',
context_instance=RequestContext(request))

That will, among other things (and depending on the
TEMPLATE_CONTEXT_PROCESSORS variable in your settings.py) populate the
request-object with a "user" field.

You can read more here:
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext


Cheers,

johan

-- 
Johan Liseborn

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to