Python

reverse and get_absolute_url ?

Can somebody help me understand the reverse and the get_absolute_url please. I really confuse and don't understand. I try to read the document but i still dont get it.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 49,126 Points

The method get_absolute_url() is intended to be defined on a Model so that model.get_absolute_url() will return a URL string that would point to this model's view. This method can be called from a template. See get_absolute_url in the docs.

The reverse() function from django.utils.reverse uses the name attributes in URLs defined by url(_) [before django 2.0] or path() [django 2.0+].

In templates, the url filter can be used in place of reverse() to obtain the URL path based on the name attribute.

Post back if you need more details. Good luck!