views:

11

answers:

2

As of the documentation, there should be variables called "debug" and "sql_queries" usable in templates if all requirements are met.

I have set the following (and checked their values with the debug toolbar):

  • DEBUG = True
  • TEMPLATE_DEBUG = True
  • TEMPLATE_CONTEXT_PROCESSORS left at its default value (containing 'django.core.context_processors.debug')
  • INTERNAL_IPS = ('127.0.0.1',) (and the debug toolbar shows REMOTE_ADDR = '127.0.0.1' under "HTTP Headers")
  • TEMPLATE_STRING_IF_INVALID = "(invalid variable '%s'!)"

When rendering a template containing {{ sql_queries }} {{ debug }}, I get (invalid variable 'sql_queries'!) (invalid variable 'debug'!) as output.

My Django version is 1.2.3. What am I missing here?

+1  A: 

In your view, are you creating a Context, or a RequestContext? It needs to be RequestContext.

Ned Batchelder
Well, I'm just using `render_to_response("some.template.file")`.
AndiDog
The docs include this text: "If you need to use context processors, render the template with a RequestContext instance instead. Your code might look something like this: render_to_response('my_template.html', my_data_dictionary, context_instance=RequestContext(request))"
Ned Batchelder
Okay that helped me find the answer, thank you very much! A `RequestContext` instance must be passed explicitly.
AndiDog
A: 

Ned Batchelder's answer led me to the right direction. A RequestContext instance must be explicitly passed when using render_to_response:

return render_to_response("some.template.file",
                          templateArguments,
                          context_instance = RequestContext(request))
AndiDog