D
D
dsendy2021-04-23 20:28:20
Django
dsendy, 2021-04-23 20:28:20

Why doesn't get_context_data() work with get()?

I have overridden the get_context_data method in my ListView :

def get_context_data(self, **kwargs):
    context = super(GoodsList, self).get_context_data(**kwargs)
    context['some_context'] = 'Some context'
    return context
This way I get the context in my template. But if I want to process the request in the same class with the get() method, then the context is no longer passed to the template, and calling the get_context_data() method in the get() method throws an exception:
object has no attribute 'object_list'
.
In general, how to properly process the request and add the context for use in the template?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-04-23
@dsendy

You need to look at the inheritance hierarchy of CBV and mixins, understand the order of calling methods, and the question will disappear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question