Thats because of an anouing thing with tuples where args=('12') is
identical to args='12', you would need to do args=('12',) to make it
work right


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com



On Tue, Jan 27, 2009 at 7:07 PM, Fluoborate <motoy...@gmail.com> wrote:
>
> Hello All,
>
> I have a question. When I use the function
> django.core.urlresolvers.reverse(), it works fine with args=(), and it
> works fine with args=(string1, string2 [, ...more strings]), and it
> even works fine with args=(anyOneCharacterLongString). However, if I
> give it args=(multiCharacterString), it does not work.
>
> For instance, from the command line:
>>>> reverse('mysite.myapp.views.onedataset', args=('6'))
> '/myapp/6/'
>>>> reverse('mysite.myapp.views.onedataset', args=('12'))
> Traceback (most recent call last):
>  File "<console>", line 1, in <module>
>  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/core/urlresolvers.py", line 254, in
> reverse
>    *args, **kwargs)))
>  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/core/urlresolvers.py", line 243, in
> reverse
>    "arguments '%s' not found." % (lookup_view, args, kwargs))
> NoReverseMatch: Reverse for '<function onedataset at 0x228ecb0>' with
> arguments '('1', '2')' and keyword arguments '{}' not found.
>
> Look at that! It broke the perfectly valid arg '12' into what seems to
> be a tuple, ('1', '2'). Why did it do that? Let's try this:
>>>> reverse('mysite.myapp.views.onedataset', args=(['12']))
> '/myapp/12/'
>>>> reverse('mysite.myapp.views.onedataset', args=(('16',)))
> '/myapp/16/'
>
> Weird, it worked. It seems that whatever Django gets as *args, it
> applies the function tuple() to it. If *args is one string, tuple()
> turns it into a tuple containing a bunch of one character strings,
> thus breaking the lookup. If *args is empty, a one character string,
> or more than one string, then it works out alright because tuple()
> cannot mangle it.
>
> The solution? If you have just one string to pass as *args, make it a
> list or tuple. It took me a bunch of frustration before I figured this
> out. Well, looking at the clock I guess it only wasted about forty
> minutes of my time. And a bunch of that was spent writing this post.
> Still, I was annoyed. This problem went completely under the radar
> during testing because I never created more than 9 entries, so the bug
> never surfaced.
>
> I thought I might be able to save somebody else some trouble. Also,
> Django could conceivably fix this pretty easily.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to