Question
How to get the current domain name in Django template?
How to get the current domain name in Django template?
Similar to {{domain}} for auth_views. I tried {{ domain }}
, {{ site }}
, {{ site_name }}
according to below documentation. It didnt work.
<p class="text-right">© Copyright {% now 'Y' %} {{ site_name }}</p>
It can be either IP address 192.168.1.1:8000
or mydomain.com
https://docs.djangoproject.com/en/5.0/ref/contrib/sites/
In the syndication framework, the templates for title and description automatically have access to a variable {{ site }}, which is the Site object representing the current site. Also, the hook for providing item URLs will use the domain from the current Site object if you don’t specify a fully-qualified domain.
In the authentication framework, django.contrib.auth.views.LoginView passes the current Site name to the template as {{ site_name }}.