post
method doesn't exist by default in DetailView
, you actually creating it not overriding, so therefore you need to fetch the object by yourself, the reason it'a available in get_context_data
is that it's already fetched inside get
method and saved in object
property.
django: DetailView: self.object raises an error when called from the method post, but it does work when called from the method get_context_data
-
30-06-2022 - |
Вопрос
I created a class that inherits from DetailView
, and I overrided the methods get_context_data
and post
. What it seems weird as mentioned in the title, is that I can call self.object
from get_context_data
but I can't from post so I had to use self.get_object()
instead. But I would like to understand why? is self.object
removed by get_context_data
? so that any method called after it cannot use it or something like that?
Thanks in advance
Решение
Не связан с StackOverflow