views:

224

answers:

1

I must have missed something in setting up a custom template context as it's never getting called.

In settings:

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django_authopenid.context_processors.authopenid",
    "web.context_processors.my_hat",
)

in web/context_processors.py

from libs.utils import get_hat, get_project, my_hats

print 'heloooo'

def my_hat(request):
    """Insert some additional information into the template context
    """
     
    import pdb
    pdb.set_trace()

    print 'hiiiiiiii'

    return {'hat': get_hat(request),
        'project': get_project(request),
        }

nothing is output and django processes view and displays template without ever hitting this. What have I missed!?

Thanks Insin, the bits I had missed:

In the view.py

return render_to_response(template, {
        'tasks': tasks,
    },
    context_instance=RequestContext(request))

In the template:

  My current hat is {{hat}}
+7  A: 

Did you remember to use RequestContext when rendering the template?

insin
No as from my extensive googling the examples don't show it!http://stackoverflow.com/questions/557460/django-having-middleware-communicate-with-views-templateshttp://stackoverflow.com/questions/1025025/django-context-processor-troublehttp://lethain.com/entry/2007/jun/14/a-django-middleware-for-google-analytics-repost/...