A possible solution using class-based classes is to create a base view class that will collect general context data and then expand it as needed for specific data and a template. In fact, the base class should not be an extension View, the extension is ContextMixinenough
The base class should look like this:
class BaseContextMixin(ContextMixin):
def get_context_data(self, **kwargs):
context_data = super(BaseContextMixin, self).get_context_data(**kwargs)
common_data_1 = ...
context_data["common_key_1"] = common_data_1
common_data_2 = ...
context_data["common_key_2"] = common_data_2
...
return context_data
:
class MyFirstView(TemplateView, BaseContextMixin):
template_name = "mir/my_first_template.html"
def get_context_data(self, **kwargs):
context_data = super(MyFirstView, self).get_context_data(**kwargs)
context_data["my_special_key"] = my_special_data
return context_data
class MySecondView(TemplateView, BaseContextMixin):
template_name = "mir/my_second_template.html"
def get_context_data(self, **kwargs):
context_data = super(MySecondView, self).get_context_data(**kwargs)
context_data["my_special_key_2"] = my_special_data_2
return context_data