views:

349

answers:

1

I am trying to create a custom context processor which will render a list of menu items for a logged in user. I have done the following:-


Within my settings.py I have

TEMPLATE_CONTEXT_PROCESSOR = (
    'django.contrib.auth.context_processors.auth',
    'mysite.accounts.context_processors.user_menu',
)

Under the accounts submodule I have *context_processors.py* with the following, for now:-

def user_menu(request):
    return {'user_menu':'Hello World'}

On my template page I have the following:-

{% if user.is_authenticated %}
Menu
{{user_menu}}
{% endif %}

The invoking view is as follows:

def profile(request):
    return render_to_response('accounts/profile.html',context_instance=RequestContext(request))

However I am unable to get the {{user_menu}} to render anything on the page, I know the user is authenticated as other sections of the template with similar checks render correctly. Am I missing something here. Please help Thank you

Edit: Thanks Ben, Daniel, I have fixed the (S) in TEMPLATE_CONTEXT_PROCESSOR, however Django now has trouble resolving the module and I get the following message

Error importing request processor module django.contrib.auth.context_processors: "No module named context_processors"

UPDATE: I fixed it by changing the path to django.core.context_processors.auth Seems like the modules have been moved around

+1  A: 

The setting name should be TEMPLATE_CONTEXT_PROCESSORS, with an S.

Daniel Roseman
Ah, Thanks... :p.. I seem to have progressed a bit more now I get the following error.. Sorry I am a newbie to both python and djangoError importing request processor module django.contrib.auth.context_processors: "No module named context_processors"
VDev
Says you fixed it by make sure every folder you create with python code has a __init__.py in it. That tells python, yo, it's a module.
TheLizardKing