views:

33

answers:

1

Hi,

I am using django generic views, how do I get access to the request in my template.

URLs:

file_objects = {
    'queryset' : File.objects.filter(is_good=True),
}
urlpatterns = patterns('',
    (r'^files/', 'django.views.generic.list_detail.object_list', dict(file_objects, template_name='files.html')),
)
+2  A: 

After some more searching, while waiting on people to reply to this. I found:

You need to add this to your URLS.py

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
)

This means that by default the request will be passed to all templates!

Mark
Not strictly true - it will be passed to all templates that are rendered using a `RequestContext`, which all generic views are.
Daniel Roseman