0

So i was digging in Django's source codes and came across these two: views.generic.list.py and views.generic.base.py

so this is line 26 in base.py in ContextMixin's get_context_data method

if self.extra_context is not None:
    kwargs.update(self.extra_context)
return kwargs

MultipleObjectMixin (line 9 in list.py) inherits ContextMixin and calls the parent class's method in the overwritten get_context_data method (line 136 in list.py)

So the extra_context variable should work and add extra context to the dictionary passed to template engine in classes that use the MultipleObjectMixin. But the questions i looked up stated that extra_context isn't supported anymore, and i ran a code that didn't work and i had to overwrite get_context_data to get what i wanted, does anyone have any explanations about this?

P.S. I checked the installed sources on my system, and it was different than the github code, so my question now is why is the repository behind from latest released versions?

Ali Ameli
  • 1
  • 2
  • You are linking to the master branch (which will become Django 2.0). You should look at the tag for the specific version you are using, e.g. 1.11. – Alasdair Aug 20 '17 at 16:37
  • I've been using generic views a LOT (subclassing them, adding mixins, etc) and have not seen this. It must be something new. But I can't think of too often that I only add things to the context that are known at compile time.. so it makes more sense to just override get_context_data anyway. – little_birdie Aug 20 '17 at 16:40
  • 1
    ContextMixin's `extra_context` was added [just over a month ago](https://github.com/django/django/commit/604341c85fe42c809d17ea2418566a48f60f78db) to the current master. – knbk Aug 20 '17 at 16:41

1 Answers1

0

I think i saw a question about extra_context which was about Djnago 1.5 or something close to that, so i assumed the feature existed and was removed and that gave me the impression that the master branch is behind from the latest release But as it seems, and @knbk pointed out, it's a newly added (or maybe revived) feature.

So, i guess this explains everything. I'd be happy to accept any more complete answer if anyone has one :) or I'll just go with my own answer to close this question.

Ali Ameli
  • 1
  • 2