Last active
January 3, 2016 08:09
-
-
Save phalt/8433810 to your computer and use it in GitHub Desktop.
Useful decorator around the django.contrib.sites package for view functions.
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
from django.conf import settings | |
from functools import wraps | |
from django.contrib.sites.models import get_current_site | |
from django.http import HttpResponseNotFound | |
def main_site_only(function): | |
"Use this decorator on views that should only be visible on your main site" | |
@wraps(function) | |
def decorator(request, *args, **kwargs): | |
if get_current_site(request).id in settings.SITE_ID: | |
return function(request, *args, **kwargs) | |
else: | |
# Change this to a TemplateResponse if you want to return a template | |
return HttpResponseNotFound() | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment