1👍
✅
Those 2 lines of code add the view as variable to the context if it was not already present. Most people never use this, but you could do something like this:
class SomeView(TemplateView):
template_name = "something.html"
title = "My list of books"
def books(self): #custom method
return Book.objects.all()
And then in your template you could reference the books method and title attribute through the view variable:
<h1>{{ view.title }}</h1>
<ul>
{% for book in view.books %}
<li>{{ book }}</li>
{% enfor %}
<ul>
Ah yes, and note that you don’t even need a custom get_context_data() method in this case
Source:stackexchange.com