Created
February 4, 2012 22:29
-
-
Save dfalk/1740720 to your computer and use it in GitHub Desktop.
django site in context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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