Login

SSL Force Middleware

Author:
careercoder
Posted:
May 24, 2014
Language:
Python
Version:
1.5
Score:
0 (after 0 ratings)

A simple way to force SSL on all pages. It's very simple at this point - the only issue I can see right now and I will address this later is if someone sends http:// in another portion of your url.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#########
# Not Currently Working, it was... something happened fixing 
#########
__license__ = "Python"
__copyright__ = "Copyright (C) 2014 Jody Fitzpatrick"
__author__ = "Jody Fitzpatrick - [email protected]"

from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect

class SSLRedirect:
    
  def process_request(self, request):
      
    if request.META['HTTP_HOST'] == 'http':
      newurl = str(request.build_absolute_uri()).replace('http://', 'https://')       
      return HttpResponsePermanentRedirect(newurl)
        

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 5 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 5 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year ago
  5. Help text hyperlinks by sa2812 1 year, 1 month ago

Comments

Please login first before commenting.