Django common dictionary available to templates

By | May 11, 2011

We need to leverage TEMPLATE_CONTEXT_PROCESSORS, the following example uses the “home” application

  1. add this to settings.py
  2. in home application, create a python file called context_processor.py
  3. in the context_processor.py add a function like this:
  4. for any templates needs to use this processor need to render the template like this
    vars = {}
    return render_to_response('home.html', vars, context_instance=RequestContext(request))
  5. use it in the templates like {{ remote_ip }}

Leave a Reply

Your email address will not be published. Required fields are marked *