Re: request object in generic view?

2010-09-09 Thread Łukasz Rekucki
On 9 September 2010 05:46, akcom  wrote:
> Is there anyway to access the request object from a generic view?
> Specifically, I'd like to access the request.user object.  I tried
> doing it as follows:
> (r'^$', 'django.views.generic.simple.direct_to_template', {'template':
> 'index.html', 'extra_context' : {'request' : request}}
> hoping that the dictionary element would be evaluated within the
> context of the view where request would be valid.
That would surely be too much magic.

>Alas I was mistaken.
>
> Any help would be much appreciated!
>

Generic views use RequestContext[1] as the context instance, so all
your context processors are executed. Just add
"django.core.context_processors.request"[2] to your
TEMPLATE_CONTEXT_PROCESSORS list and you'll have the "request" object
available in all your templates


[1]: 
http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext
[2]: 
http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request


-- 
Łukasz Rekucki

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



request object in generic view?

2010-09-08 Thread akcom
Is there anyway to access the request object from a generic view?
Specifically, I'd like to access the request.user object.  I tried
doing it as follows:
(r'^$', 'django.views.generic.simple.direct_to_template', {'template':
'index.html', 'extra_context' : {'request' : request}}
hoping that the dictionary element would be evaluated within the
context of the view where request would be valid.  Alas I was
mistaken.

Any help would be much appreciated!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.