[Django]-Multiple Templates in Generic ListView in Django

6👍

Yes, you can use the same URL for both situations and set the appropriate template by checking the value of request.is_ajax(). Now instead of using the template_name class attribute, override the get_template_names() method (this method should return a list of templates, the first one found will be used):

class MyView(ListView):
    def get_template_names(self):
        if self.request.is_ajax():
            return ['list_template.html']
        return ['full_list_template.html']

Leave a comment