Correct me if I'm wrong, but I'm not sure this resolves the core problem. In your example, I still need to add something (in this case, 'context_instance=RequestContext(request)') to my "render_to_response" statements. I'd like to eliminate that completely since it requires a developer to add something to the render_to_response to get the username to render. If the developer forgets to add that, then the username doesn't display.
Long story short, is there a way to get the username to render using a call that lives in the template and doesn't require repeated references to a value in the view? In other words, if I have five pages and five distinct methods in the view that each have a render_to_response, how can I avoid adding five 'context_instance=RequestContext(request)' values to my render_to_response statements? I apologize in advance if using RequestContext does resolve this issue -- still learning! On Jun 24, 10:02 am, "Johan Liseborn" <[EMAIL PROTECTED]> wrote: > 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/#subclass... > > 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 -~----------~----~----~----~------~----~------~--~---