5

I need the request object in all admin templates. In frontend templates, I can achieve this by rendering the template with RequestContext:

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

With that, I can access the request object in frontend:

{{ request.path }}

How can I do this for all admin views in Django 1.2?

Martin
  • 4,170
  • 6
  • 30
  • 47

1 Answers1

8

The request should be available in the admin templates if you have 'django.core.context_processors.request' added to your TEMPLATE_CONTEXT_PROCESSORS in your settings.py

Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • 1
    should this only be needed to access `request`-properties within **admin-templates**? using django 1.5 in combination with `django.shortcuts.render` which should implicitly include request it appears that this is needed for own (non-admin) views as well. can you confirm or even explain? (btw, i'm fairly new to django so might oversee/misunderstand simple things...) – antiplex May 08 '13 at 14:50
  • an older [answer](http://stackoverflow.com/a/2551976/294930) suggests adding `'django.core.context_processors.request'` also for general access to request properties (the session-dict in the linked example)... btw, this [hint showing how to append values within settings instead of overwriting](http://stackoverflow.com/a/9233283/294930) also seems worth mentioning in this context ;) – antiplex May 08 '13 at 15:00