Problem
I'm currently trying to upgrade to Django 1.10.3
from Django 1.9.8
. Currently my tests are failing however, because for some reason Django is trying to translate/internationalize my URLs when I reverse()
them.
I've not changed anything when it comes to internationalization and would very much like to turn this "feature" off. Not only is it failing a lot of tests, but there are also some projects which have to refer to the URLs of this website statically. This means the URL on this website are not allowed to change (or I would have to edit them for every translation Django comes up with, which would be a real pain).
Error
The actual error I'm encountering in my tests is the following:
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'
It's obvious Django is trying to do something with the language code provided in the settings for this project.
What have I tried
I have tried setting the USE_I18N
setting to False
. I have also tried this for USE_L10N
. I also tried removing the LANGUAGE_CODE
specified in my settings, but then the error thrown refers to the en-us
language code instead of the nl-nl
language code. I also tried installing the LocaleMiddleware
to see if I could at least get the error to stop showing, but unfortunately this also didn't work.
Question
How can I turn off URL internalization/translation in Django. Or what would be a good alternative if this is not possible?
Thanks in advance.
test_index.py
? – Mcmillian