You should be able to access the parameter with self.kwargs['name']
. Further, get_queryset
should return a queryset instead.
You also need to use pk
instead of name
in your URL if you want to use DetailView
generic view. After that you only need to define model = Customer
and slug_field = 'name'
in your customerDetailView
class and it should work. You do not need to access self.kwargs['name']
at all. [source]
If you really want to use <name>
in your URL, you also need to change slug_url_kwarg
to name
(in addition to slug_field = 'name'
:
class customerDetailView(DetailView):
context_object_name = 'customerDetail'
template_name = "customer.html"
allow_empty = True
model = Customer
slug_field = 'name'
slug_url_kwarg = 'name'
# no need to override any methods here
or override get_object
by:
def get_object(self):
return get_object_or_404(Customer, name=self.kwargs['name'])
without modifying slug_field
and slug_url_kwarg
in your class.