[Answered ]-How to choose template in DetailView based on a field of the model shown?

1👍

You can override the get_template_names method, so:

class AlbumDetailView(DetailView):
    model = Album
    template_name = 'bilddatenbank/album_detail.html'

    def get_template_names(self):
        if self.object.type == 't':  # special type
            return ('bilddatenbank/other_template.html',)
        return super().get_template_names()

Leave a comment