I have just stated to learn Django. So far I pass dynamic URL parameters into reverse function inside the get_absolute_url() method in the following ways:
# By using kwargs:
def get_absolute_url(self):
return reverse('book-detail', kwargs={'id':self.id})
# Or by using the args:
def get_absolute_url(self):
return reverse('book-detail', args=[self.id])
# But I found several examples of the following code:
def get_absolute_url(self):
return reverse('book-detail', args=[str(self.id)]
I have used the simple library app to pass id of the book into URL in order to get book details. All three variants work fine without any problem. Can somebody explain to me why and when we should use args=[str(self.id)]?