Relative URLs

Let's discuss how to use template tagging to create relative URLs.

What are relative URLs?

Traditionally, when we use an anchor tag with an href, we have to pass in the hardcoded path to the file. However, this method is not suitable if we want our Django project to work on any system. So let’s see how to replace a hardcoded URL path in an href with a URL template.

Using the url tag

The best way to replace a hardcoded URL path in a Django template is to use the url tag. The syntax for the url tag is as follows:

{% url
...