Search⌘ K
AI Features

Relative URLs

Understand how to implement relative URLs in Django templates using the url tag. This lesson teaches you to replace fixed URL paths with dynamic references by name and parameters, thereby making your Django project adaptable across systems. You will also learn how to handle application-specific URLs using app_name and path names.

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
...