coding utf-8 from functools import wraps from django core import urlre

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
from functools import wraps
from django.core import urlresolvers
from django.conf import settings
from django.utils import translation
#### Первый вариант
def reverse_decorator(f):
@wraps(f)
def wrapper(*args, **kw):
locale = kw['kwargs'].pop('locale', translation.get_language())
path = f(*args, *kw)
if settings.USE_I18N:
path = u'/' + locale + path
return path
return wrapper
urlresolvers.reverse = reverse_decorator(urlresolvers.reverse)
##### Второй
def reverse(viewname, urlconf=None, args=[], kwargs={}):
locale = kwargs.pop('locale', translation.get_language())
path = django_reverse(viewname, urlconf, args, kwargs)
if settings.USE_I18N:
path = u'/' + locale + path
return path
django_reverse = urlresolvers.reverse
urlresolvers.reverse = reverse