KeyError: ‘en-us’ when doing a reverse() lookup in

If you’re getting an error like this:

... in reverse_dict
return self._reverse_dict[language_code]
KeyError: 'en-us'

If your file contains a reverse() call, that is the reason.  You’re calling reverse before all the urls are loaded and everything is ready.  You need to use reverse_lazy() instead.:

{'post_reset_redirect': reverse('password_reset_done'),
'html_email_template_name': 'registration/html_password_reset_email.html'},

Change the reverse() call into a reverse_lazy() call and the problem will go away!

This entry was posted in django, python, Web Programming. Bookmark the permalink.

Comments are closed.