RequestContext direct_to_template, TEMPLATE_CONTEXT_PROCESSORS

Posted: August 5th, 2010 | Author: | Filed under: Django | Tags: , | 4 Comments »

If you are wondering why you can’t use {{ request }} in your templates while using
direct_to_template then you probably forgot to edit your TEMPLATE_CONTEXT_PROCESSORS in settings.py

The default TEMPLATE_CONTEXT_PROCESSORS is without the django.core.context_processors.request

TEMPLATE_CONTEXT_PROCESSORS = (
      "django.contrib.auth.context_processors.auth",
      "django.core.context_processors.request",
      "django.core.context_processors.debug",
      "django.core.context_processors.i18n",
      "django.core.context_processors.media",
      "django.contrib.messages.context_processors.messages",
)

Hope this works for you.


4 Comments on “RequestContext direct_to_template, TEMPLATE_CONTEXT_PROCESSORS”

  1. 1 Ben said at 1:03 am on April 30th, 2011:

    Thank you! Am working on Appengine and had commented that preprocessor out along with a bunch of others because AE doesn’t play nicely with some of them. Appears to work fine now that I’ve uncommented it though.

  2. 2 Hulk said at 7:34 pm on May 25th, 2011:

    Is there a way around declaring the request as a global variable? I’m using “list_detail.object_list” to contain my “request, queryset, and template_name” in my views. Why wouldn’t I be able to access {{ request }} since it’s in the object_list that I’m returning?

    I can’t access the {{ request }} in the template, and I was wondering if there was a way to pass the request to the template without doing the template_context_processors stuff.

  3. 3 Ivens said at 10:41 pm on July 8th, 2011:

    Not true. In my case, settings.py was already with that line and still didn’t work.

  4. 4 Tom Vaughan said at 5:17 pm on September 14th, 2011:

    See also: http://blog.madpython.com/2010/04/07/django-context-processors-best-practice/


Leave a Reply