Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

make Django 1.10 compatible #35

Merged
merged 1 commit into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion sslify/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,28 @@
from django.conf import settings
from django.http import HttpResponsePermanentRedirect

try:
# Django 1.10
from django.utils.deprecation import MiddlewareMixin
except ImportError:
# Django <1.10
class MiddlewareMixin(object):
def __init__(self, get_response=None):
self.get_response = get_response
super(MiddlewareMixin, self).__init__()

def __call__(self, request):
response = None
if hasattr(self, 'process_request'):
response = self.process_request(request)
if not response:
response = self.get_response(request)
if hasattr(self, 'process_response'):
response = self.process_response(request, response)
return response


class SSLifyMiddleware(object):
class SSLifyMiddleware(MiddlewareMixin):
"""Force all requests to use HTTPs. If we get an HTTP request, we'll just
force a redirect to HTTPs.

Expand Down
7 changes: 3 additions & 4 deletions test_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = patterns(
'',
urlpatterns = [
# Examples:
# url(r'^$', 'test_project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
]