Redirect url if invalid url
I have this method in my book:
def get_absolute_url(self):
return "/book/%s/%s/%i/%i/" % ( self.book_title, self.book_editor, self.book_pages, self.id)
So the URLs for each book look like this:
example.com/book/the-bible/gesu-crist/938/12/
I want that if there is an error in the url, I redirect to the real url using book.id at the end of the url.
For example, if I go to:
example.com/book/A-bible/gesu-crist/938/12/
I will be redirected to:
example.com/book/the-bible/gesu-crist/938/12/
How can i do this?
+2
a source to share