1👍
create a Mixin and override get_context_data()
, put there all your common stuff, add this mixin to all your views that need this behaviour
class CommonMixin(object):
def get_context_data(self, **kwargs):
context = super(CommonMixin, self).get_context_data(**kwargs)
context['common_value'] = 'VALUE1'
return context
class App1View(CommonMixin, ListView):
...
class App2View(CommonMixin, CreateView):
...
if you use function view, write a function that acts as get_context_data
and use it in each view.
you can create a custom tag, but is possible that this will introduce more computational cost.
Another approach can be to write a custom context processor but this will impact ALL your views.
👤sax
Source:stackexchange.com