Hello kartik,
The variation of the context processor I use is:
from django.contrib.sites.shortcuts import get_current_site
from django.utils.functional import SimpleLazyObject
def site(request):
return {
'site': SimpleLazyObject(lambda: get_current_site(request)),
}
The SimpleLazyObject wrapper makes sure the DB call only happens when the template actually uses the site object. This removes the query from the admin pages. It also caches the result.
and include it in the settings:
TEMPLATE_CONTEXT_PROCESSORS = (
...
"module.context_processors.site",
....
)
In the template, you can use {{ site.domain }} to get the current domain name.
Hope this work!!
Thank You!!