I'm using Django version 2.1.
I want to create this type of URL Path in my Project: www.example.com/bachelor/germany/university-of-frankfurt/corporate-finance
Is it possible to do it in Django?
I'm using Django version 2.1.
I want to create this type of URL Path in my Project: www.example.com/bachelor/germany/university-of-frankfurt/corporate-finance
Is it possible to do it in Django?
Yes, say for example that you have a slug for an
Author
, and one for aBook
, you can define it as:Then the view looks like:
The view thus takes two extra parameters
author_slug
(the slug for the author), andbook_slug
(the slug for the book).If you thus query for
/book/shakespeare/romeo-and-juliet
, thenauthor_slug
will contains'shakespeare'
, andbook_slug
will contain'romeo-and-juliet'
.We can for example look up that specific book with:
Or in a
DetailView
, by overriding theget_object(..)
method [Django-doc]:or for all views (including the
DetailView
), by overriding theget_queryset
method: