Difference between RequestContext and Context?

169 views
Skip to first unread message

gamingdroid

unread,
Mar 14, 2011, 4:16:04 AM3/14/11
to Django users
1. So beyond the fact that RequestContext can accept a dictionary with
values to be included in the Context, what is the difference between
RequestContext and Context?

I tried reviewing the source code, but it still isn't really clear
(i.e. meaning I didn't quite understand the source code).

2. Why is it that Context automatically loads some context processors
while RequestContext does NOT?

At least it almost seem like it, because when I tried to use
RequestContext, I had to include
''django.contrib.auth.context_processors.auth'' in the
TEMPLATE_CONTEXT_PROCESSOR variable in settings.py for the admin site
to work, but did not when just using the standard Context.

Tom Evans

unread,
Mar 14, 2011, 9:16:08 AM3/14/11
to django...@googlegroups.com

Context doesn't 'load' (execute) any context processors. All context
processors are callables that take a request as their only argument,
this alone should convince you that a standard Context doesn't call
any context processors.

As for the differences between Context and RequestContext, the docs
are quite clear:

http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-context-requestcontext


Cheers

Tom

gamingdroid

unread,
Mar 14, 2011, 11:09:39 AM3/14/11
to Django users
I see, so I completely misunderstood RequestContext.

There is only two differences, RequestContext takes a HttpRequest
object as it's first argument and automatically includes
TEMPLATE_CONTEXT_PROCESSOR dictionaries into the context.

Question then is why using RequestContext forced me to include
'django.contrib.auth.context_processors.auth' in
TEMPLATE_CONTEXT_PROCESSOR for the admin section to work, while just
using Context did not? That suggest Context somehow get's
django.contrib.auth.context_processors.auth....

Thanks!

On Mar 14, 6:16 am, Tom Evans <tevans...@googlemail.com> wrote:
> http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-c...
>
> Cheers
>
> Tom

Daniel Roseman

unread,
Mar 15, 2011, 3:53:12 AM3/15/11
to django...@googlegroups.com
On Monday, March 14, 2011 3:09:39 PM UTC, gamingdroid wrote:
I see, so I completely misunderstood RequestContext.

There is only two differences, RequestContext takes a HttpRequest
object as it's first argument and automatically includes
TEMPLATE_CONTEXT_PROCESSOR dictionaries into the context.

Question then is why using RequestContext forced me to include
'django.contrib.auth.context_processors.auth' in
TEMPLATE_CONTEXT_PROCESSOR for the admin section to work, while just
using Context did not? That suggest Context somehow get's
django.contrib.auth.context_processors.auth....

Thanks!
 
I am confused by your question. The choice of Context or RequestContext only applies to your own views. It doesn't affect the admin site in any way. What do you mean when you say you needed to add something to get the admin section to "work"? How did it not work when you didn't?
--
DR.
Reply all
Reply to author
Forward
0 new messages