Jul 13

Extending different base template for ajax requests in Django

While there are different ways to specify what should be rendered what should server return when ajax request is performed, using yesno template filter can be simplest.

This can be especially useful in situations when using without javascript should fail gracefully or when working with existing views.

 {% extends request.is_ajax|yesno:“base_ajax.html,base.html” %}

For this to work, django.core.context_processors.request should be installed in TEMPLATE_CONTEXT_PROCESSORS.