Skip to content

Instantly share code, notes, and snippets.

@drewtempelmeyer
Created January 30, 2013 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewtempelmeyer/4669799 to your computer and use it in GitHub Desktop.
Save drewtempelmeyer/4669799 to your computer and use it in GitHub Desktop.
Django SSL Mixin
from django.conf import settings
from django.http import HttpResponseRedirect
class SSLRequiredMixin(object):
def dispatch(self, request, *args, **kwargs):
if settings.DEBUG is False and request.is_secure() is False:
host = request.get_host()
url = 'https://%s%s' % (host, request.get_full_path())
return HttpResponseRedirect(url)
return super(SSLRequiredMixin, self).dispatch(request, *args,**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment