Question

I'm using djangio-localeurl to provide locale switching based on my URLs. It works fine pretty much apart from a little hiccup.

In some of my class-based views, I have been using a lazy reverse function else I get errors about missing URL patterns. This was something due to the order in which files were imported. One explanation read:

Since the decorators of your views are evaluated during parsing urls.py you have an 'chicken - egg' problem. The method reverse() can't be used since urls.py is not read.

It seems that django-localeurl monkey-patches Django's internal reverse function. This change works fine but my lazy_reverse function gives me issues. Now when I run my tests, I get errors at the places where I've used this lazy_reverse function. Here's my lazy_reverse function code:

from django.utils.functional import lazy
from django.core import urlresolvers

reverse_lazy = lambda name=None, *args : lazy(urlresolvers.reverse, str)(name, args=args)

The error I keep getting is:

TypeError: Lazy object returned unexpected type.

I can seem to understand what is causing this. This issue seems to disappear the moment I remove localeurl from my INSTALLED_APPS setting.

Any ideas on how to resolve this?

Thanks

Was it helpful?

Solution

It was an error in lazy_reverse function it seems. I've not modified my lazy_reverse function to return unicode instead of str. Here's what it looks like:

from django.utils.functional import lazy
from django.core.urlresolvers import reverse

reverse_lazy = lazy(reverse, unicode) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top