Django Absolute url Django Absolute url codeigniter codeigniter

Django Absolute url


You can get absolute url in 2 ways in django.

One is build your custom template tag by using HttpRequest.build_absolute_uri() method from HttpRequest

Or simply use following line in your django template.

<a href="{{ request.get_host }}{% url your_url_name %}">Link</a>

See this link for details:https://docs.djangoproject.com/en/2.1/ref/request-response/#django.http.HttpRequest.get_host


If you have a URL path in your urls.py file defined like this:

path('user/', views.user, name='user_list')

Then you can call this URL in the template like this:

<a href="{% url 'user_list' %}">Users</a>

Check https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#url for details.

For absolute URL you can use:

<a href="{{ request.get_host }}{% url 'user_list' %}">Users</a>