Django Locale URL – 404 bug
by gNesher on 26/03/2012Django Locale URL (django-localeurl) allows you to easily manage multiple languages in your site by adding the language code to the URL. Sadly there is a fairly significant bug when dealing with non-existing urls (404 errors) on live sites (DEBUG=False). Localeurl is unable to match a language (as the url is invalid) and breaks down – ignoring the 404 template (this seems to happen for 500 errors as well).
Since the bug only happens when debugging is turned off I was only able to catch this when I was setting a live site, and had to come up with the following quick fix (lines 79/80)
try: url.startswith(urlresolvers.get_script_prefix()) except ValueError: raise Http404
This will basically try to resolve the language prefix, and raise a 404 error if an error occurs. This is not a perfect fix (as there might be other errors preventing the script from fetching the url prefix) but it does provide an instant fix.
This still leaves me with no real alternatives for localeurl, so if you know of a better alternative do leave a comment.















