mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #26271 -- Fixed i18n_patterns resolution when no language is active
Thanks Marten Kenbeek for the report.
This commit is contained in:
parent
2109975e90
commit
95ca01f999
@ -11,6 +11,7 @@ import functools
|
||||
import re
|
||||
from importlib import import_module
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.utils import lru_cache, six
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
@ -388,7 +389,7 @@ class LocaleRegexURLResolver(RegexURLResolver):
|
||||
|
||||
@property
|
||||
def regex(self):
|
||||
language_code = get_language()
|
||||
language_code = get_language() or settings.LANGUAGE_CODE
|
||||
if language_code not in self._regex_dict:
|
||||
regex_compiled = re.compile('^%s/' % language_code, re.UNICODE)
|
||||
self._regex_dict[language_code] = regex_compiled
|
||||
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.http import HttpResponsePermanentRedirect
|
||||
from django.middleware.locale import LocaleMiddleware
|
||||
@ -75,6 +76,8 @@ class URLPrefixTests(URLTestCaseBase):
|
||||
self.assertEqual(reverse('prefixed'), '/en/prefixed/')
|
||||
with translation.override('nl'):
|
||||
self.assertEqual(reverse('prefixed'), '/nl/prefixed/')
|
||||
with translation.override(None):
|
||||
self.assertEqual(reverse('prefixed'), '/%s/prefixed/' % settings.LANGUAGE_CODE)
|
||||
|
||||
@override_settings(ROOT_URLCONF='i18n.patterns.urls.wrong')
|
||||
def test_invalid_prefix_use(self):
|
||||
|
Loading…
Reference in New Issue
Block a user