[Answer]-Meta: Why are there no custom class based views?

1👍

All the generic class-based views can be extended and their methods overridden, as defined in the documentation. For example, if you wanted extra context variables defined in addition to the ones the view defines itself, just add them using the get_context_data method:

class CustomDetailView(DetailView):
    model = MyModel
    def get_context_data(self, **kwargs):
        context = super(CustomDetailView, self).get_context_data(**kwargs)
        context.update({
            "foo": "bar",
            "baz": 999,
        })
        return context

Alternatively, you may want to define a certain mixin which would be included in every view as needed.

Leave a comment