Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a context processor to expose the current site
- Loading branch information
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,18 @@ | |||
from django.conf import settings | from django.conf import settings | ||
from django.contrib.sites.models import Site, RequestSite | |||
|
|
||
def admin_media_prefix(request): | def admin_media_prefix(request): | ||
return {'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX } | return {'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX } | ||
|
|||
def current_site(request): | |||
''' | |||
A context processor to add the "current_site" to the current Context | |||
''' | |||
context_name = 'CURRENT_SITE' | |||
|
|||
try: | |||
current_site = Site.objects.get_current() | |||
return { name: current_site, } | |||
except Site.DoesNotExist: | |||
# always return a dict, no matter what! | |||
return {name: RequestSite(request)} |