Skip to content

Commit 753be70

Browse files
noirbizarreakx
authored andcommitted
Ensure compatibility with Django 1.10+ middlewares
1 parent 264f447 commit 753be70

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

django_babel/middleware.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
from django.utils.translation import get_language
55
from threading import local
66

7+
try:
8+
from django.utils.deprecation import MiddlewareMixin
9+
except ImportError:
10+
# Not required for Django <= 1.9, see:
11+
# https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware
12+
MiddlewareMixin = object
13+
714

815
__all__ = ['get_current_locale', 'LocaleMiddleware']
916

@@ -19,7 +26,7 @@ def get_current_locale():
1926
return getattr(_thread_locals, 'locale', None)
2027

2128

22-
class LocaleMiddleware(object):
29+
class LocaleMiddleware(MiddlewareMixin):
2330

2431
"""Simple Django middleware that makes available a Babel `Locale` object
2532
via the `request.locale` attribute.

0 commit comments

Comments
 (0)