Using Django class-based views, how can I return a different template if request.is_ajax
问题 I find Django's request.is_ajax a very useful way to add progressive enhancement via JS and still keep DRY in my views. However, I want to use class-based views and render with a different template if request.is_ajax. It is not clear to me how I can override my default "template_name" and make the template loading conditional in class-based views. How can I do this? 回答1: The appropriate way to do this is to override the methods provided by the TemplateResponseMixin. If you simply need to