Do not internationalize / translate URLs

Problem

I am currently trying to switch to Django 1.10.3s Django 1.9.8. My tests currently do not work, because for some reason Django tries to translate / internationalize my URLs when I have reverse()them.

I did not change anything when it came to internationalization, and would really like to disable this feature. Not only does it fail many tests, but there are also some projects that should link statically to the URLs of this site. This means that the URL on this website is not allowed to be changed (or I will have to edit them for each Django translation, which would be a real pain).


Error

The actual error that I encounter in my tests is this:

Traceback (most recent call last):
  File "/tests/unit/views/test_index.py", line 14, in setUp
    self.url = reverse('indexpage')
  File "/local/lib/python2.7/site-packages/django/urls/base.py", line 91, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 346, in _reverse_with_prefix
    possibilities = self.reverse_dict.getlist(lookup_view)
  File "/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 243, in reverse_dict
    return self._reverse_dict[language_code]
KeyError: 'nl-nl'

, Django - , .


USE_I18N False. USE_L10N. LANGUAGE_CODE, , en-us nl-nl. LocaleMiddleware, , , , , , .


/ URL Django. , ?

.

+4
2

( ). , , urls.py , . django :

from django.urls import reverse
reverse('indexpage')

, . , .

+11

USE_I18N = False

Vijesh Venugopal, , URL- : -

urlpatterns += [
    url("^", include("your_app.urls")),
]

urlpatterns = i18n_patterns(
    # Change the admin prefix here to use an alternate URL for the
    # admin interface, which would be marginally more secure.
    url("^admin/", include(admin.site.urls)),
)
0

Source: https://habr.com/ru/post/1660391/


All Articles