pistacchio
pistacchio

Reputation: 58933

django.core.context_processors.request Not working

I have this in my setting.py:

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
    'django.core.context_processors.static',
    'django.contrib.auth.context_processors.auth',
)

Whenever I try to access the request in a template (for example {{ request.user.get_profile.custom_username }}) I get no result. I think the request is not added to the template, because if i force the request in to the Context (in the view), I can access it:

ctx = {}
#ctx['request'] = request
return render_to_response('index.html', ctx)

Any help? Thanks

Upvotes: 1

Views: 980

Answers (2)

ustun
ustun

Reputation: 7041

Use the render shortcut instead, easier to remember:

return render(request, 'index.html', ctx)

Upvotes: 7

JamesO
JamesO

Reputation: 25956

RequestContext needs to be passed to the template, in django 1.3. you can use render to automatically include this or if you need to use render_to_response try:

return render_to_response('index.html',
                          ctx,
                          context_instance=RequestContext(request))

Upvotes: 2

Related Questions