Reputation: 3841
Django's generic view class ListView has object_list as context variable, what is the context variable for the DetailView?
My view is,
class MyDetail(DetailView):
model = Mymodel
Upvotes: 1
Views: 1068
Reputation: 1
You can change the context object name by using :
context_object_name = 'your_object_name'
Include this in the class in your View. By default, the object name is 'object' , but it is always good to use an object name of your choice. It makes it more intuitive!
Upvotes: 0
Reputation: 150188
The context data for a DetailView
class contains the "object"
key, which points to the object that the view is operating on.
You can use a different key if you override the get_context_data()
method of the view, e.g.:
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["my_object"] = self.object
return context
Upvotes: 3