Django provides tools for performing URL reversing that match the different layers where URLs are needed:
In templates: Using the url template tag.
In Python code: Using the reverse() function.
In higher level code related to handling of URLs of Django model instances: The get_absolute_url() method.