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:
[sourcecode language=’Python’]python manage.py shell
>> from django.core.urlresolvers import reverse
>> reverse(’nameofurl’)
[/sourcecode]
If there are arguments in the URLS field (for instance passing in the slug):
[sourcecode language=’python’] >> reverse(’nameofurl’, ’slug’) [/sourcecode]
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:
[sourcecode language=’python’]Traceback (most recent call last):
File “
File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 297, in reverse
return iri_to_uri(u’/’ + get_resolver(urlconf).reverse(viewname, *args, **kwargs))
File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 282, in reverse
if lookup_view in self.reverse_dict:
File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 221, in _get_reverse_dict
self._reverse_dict[pattern.callback] = (pattern,)
File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 178, in _get_callback
self._callback = get_callable(self._callback_str)
File “/Users/azimi/Code/Python/Django/django-trunk/django/utils/functional.py”, line 130, in wrapper
result = func(*args)
File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 47, in get_callable
lookup_view = getattr(__import__(mod_name, {}, {}, [”]), func_name)
File “/website/xmlrpc.py”, line 8, in
dispatcher = SimpleXMLRPCDispatcher() # Python 2.4
TypeError: __init__() takes exactly 3 arguments (1 given)
>>> reverse(’homepage’)
Traceback (most recent call last):
File “
File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 297, in reverse
return iri_to_uri(u’/’ + get_resolver(urlconf).reverse(viewname, *args, **kwargs))
File “/Library/Python/2.5/site-packages/django/core/urlresolvers.py”, line 284, in reverse
raise NoReverseMatch
NoReverseMatch
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.





