Reputation: 317
I'm trying to make conditionnal extends in a template :
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
In my view :
def new(request):
snippet_form = SnippetForm()
return render_to_response('new.html', {
'snippet_form': snippet_form,
}, context_instance=RequestContext(request))
But request.is_ajax always return false !
If I call request.is_ajax in my view, it contains the good value.
def new(request):
snippet_form = SnippetForm()
ajax = request.is_ajax()
return render_to_response('new.html', {
'snippet_form': snippet_form,
'ajax': ajax
}, context_instance=RequestContext(request))
And in my template :
{% extends ajax|yesno:"base_ajax.html,base.html" %}
That's works but I'd prefer use the first solution !
Any ideas ?
(I'm using the jquery load function)
Upvotes: 1
Views: 774
Reputation: 1638
Do you have the 'request' context processor enabled? The list called TEMPLATE_CONTEXT_PROCESSORS shloud have this string in it:
django.core.context_processors.request
It is off by default.
Upvotes: 2