Django and URLS naming

         · ·     

Django URLs naming can be a pain sometimes, unless it is just me but an easy way to debug is to use Django’s shell and import urlresolvers:

</p> <p>python manage.py shell</p> <p>>> from django.core.urlresolvers import reverse<br /> >> reverse(‘nameofurl’)<br />

If there are arguments in the URLS field (for instance passing in the slug):

<br /> >> reverse(‘nameofurl’, ‘slug’) [/sourcecode]<br />

Then it should resolve the name to the URL path needed. If it doesn’t, well something is wrong. We got a weird Traceback when using Python 2.5 though:

<br /> Traceback (most recent call last):<br /> File “<console>“, line 1, in <module><br /> File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 297, in reverse<br /> return iri_to_uri(u’/’ + get_resolver(urlconf).reverse(viewname, *args, **kwargs))<br /> File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 282, in reverse<br /> if lookup_view in self.reverse_dict:<br /> File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 221, in _get_reverse_dict<br /> self._reverse_dict[pattern.callback] = (pattern,)<br /> File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 178, in _get_callback<br /> self._callback = get_callable(self._callback_str)<br /> File “/Users/azimi/Code/Python/Django/django-trunk/django/utils/functional.py”, line 130, in wrapper<br /> result = func(*args)<br /> File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 47, in get_callable<br /> lookup_view = getattr(import(mod_name, {}, {}, [“]), func_name)<br /> File “/website/xmlrpc.py”, line 8, in </module><module><br /> dispatcher = SimpleXMLRPCDispatcher() # Python 2.4<br /> TypeError: init() takes exactly 3 arguments (1 given)<br /> >>> reverse(‘homepage’)<br /> Traceback (most recent call last):<br /> File “<console>“, line 1, in <module><br /> File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 297, in reverse<br /> return iri_to_uri(u’/’ + get_resolver(urlconf).reverse(viewname, *args, **kwargs))<br /> File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 284, in reverse<br /> raise NoReverseMatch<br /> NoReverseMatch<br /> </module></console></module></console>

Looks like something is broken in support for python 2.5 on OS X with django, but I wonder if it is just us thats found this.

comments powered by Disqus