(In a view)
request.scheme # http or https
request.META[‘HTTP_HOST’] # example.com
request.path # /some/content/1/
(In a template)
{{ request.scheme }}
{{ request.META.HTTP_HOST }}
{{ request.path }}
Example:
Using Django sites
INSTALLED_APPS = [
...
"django.contrib.sites",
...
]
MIDDLEWARE = [
...
"django.contrib.sites.middleware.CurrentSiteMiddleware",
...
]
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
current_site.domain
{{request.site.domain}}
{{request.site.name}}