My url is structured in this way:
example.com/category/subcategory/name
Right now I'm using a DetailView and it detects the url when I write it but it resolves positively to any address that includes the right name because that name is unique so what I need to check is that the name corresponds to the subcategory and this subcategory corresponds to the main category.
For example my desired url is:
http://example.com/animal/cat/garfield
It resolves alright with a 200 code. However, when I write:
http://example.com/insect/cat/garfield
It also resolves as a 200 instead of a 404.
How do I check those parameters in my view?
My urls.py
path('<str:category>/<str:subcategory>/<str:slug>', views.AnimalDetailView.as_view(), name="animal_detail")
My view:
class AnimalDetailView(DetailView):
model = Animal
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['now'] = timezone.now()
return context