Look at the basic implementation of SingleObjectMixin ("original" get_context_data ).
It simply returns **kwargs as a context (dictionary), adding an editable object with the specified key.
def get_context_data(self, **kwargs): context = kwargs context_object_name = self.get_context_object_name(self.object) if context_object_name: context[context_object_name] = self.object return context
In DetailView , quarts are “magically plucked” from what they call it / passes in these quarts. In your case, it will be BaseDetailView.get() .
class BaseDetailView(SingleObjectMixin, View): def get(self, request, **kwargs): self.object = self.get_object() context = self.get_context_data(object=self.object) return self.render_to_response(context)
Subsequently, it is used by many presentation classes (as in render_to_response(self.get_context_data) ), which passes the original context dictionary to self.response_class , which by default is django.template.TemplateResponse .
TemplateResponse knows how to make itself, and in its resolve_context function, finally converts the dictionary into django.template.Context
You really can completely track the source path from the source method to the end.
Yuji 'Tomita' Tomita
source share