Skip to content

Instantly share code, notes, and snippets.

@dfalk
Created February 4, 2012 22:29
Show Gist options
  • Save dfalk/1740720 to your computer and use it in GitHub Desktop.
Save dfalk/1740720 to your computer and use it in GitHub Desktop.
django site in context
#myproject/context_processors.py:
from django.contrib.sites.models import Site
def site(request):
'''
A context processor to add the current site to the current Context
'''
try:
site = Site.objects.get_current()
return {
'site': site,
}
except Site.DoesNotExist:
# always return a dict, no matter what!
return {'site':''} # an empty string
#myproject/settings.py:
CONTEXT_PROCESSORS += ['myproject.context_processors.site']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment