Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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">&copy; 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/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

You can use {{ request.get_host }}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading