On Sun, 2008-12-21 at 23:58 -0800, patrick91 wrote:
> On 22 Dic, 02:17, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:
> > Certainly a bit unexpected. Can you paste the relevant lines from your
> > URL Conf file, please?
> >
> > Regards,
> > Malcolm
> 
> Sure :)
> here it is:
> url(r'foglio/(?P<number>[0-9]+)/$', views.show_worksheet,
> name='show_worksheet'),

Okay, nothing unexpected there. If I use the same lines with a dummy
view file, things certainly seem to work.

The confusing thing here is that the url template tag is a relatively
simple wrapper around reverse(), so there aren't many places for things
to go wrong. Still, let's see what might be happening. I'm assuming in
what follows that you're either running Django 1.0.2 or something later
from the 1.0.X branch or Django trunk. All those versions have basically
the same code in place with all the relevant fixes for reverse().

Add some debug printing to django/template/defaulttags.py in the URLNode
class. In particular, in the render() method where it says

        args = [arg.resolve(context) for arg in self.args]
        
(line 361 in 1.0.X, line 371 in trunk).

What I'm interested in seeing is what are the values and types of the
elements in the args list. So the output of something like

        print [(repr(x), type(x)) for x in args]

would be interesting. Somehow -- and I don't know how or why, yet -- the
value of worksheet.number might not be turning out as expected. Although
the error message does make it seem like you're passing in a number
correctly.

I'll admit I'm grasping at straws a bit here, but this is the kind of
thing that you really have to debug at the source, line by line.
Ideally, we need to work out if the exact same data, of the exact same
type is being passed into the reverse() calls for the tag version. If it
is the exact same piece of data, there's something else going on.
Somehow, when you're running under the web server, the setup is subtly
different to the shell code. That's going to be a little tougher to
debug.

Oh ... other idea. Try some experiments like this:

        In [3]: from django.template import Template, Context
        
        In [4]: t = Template("{% url show_worksheet 5537 %}")
        
        In [5]: t.render(Context())
        Out[5]: u'/foglio/5537/'

That shows the url tag is working in my setup when I pass in a constant
argument. Perhaps you can arrange a shell-prompt version with
worksheet.number set up exactly as in the template that is failing for
you. Would be interesting to see if you can make things fail for the url
tag at the shell prompt whilst reverse() for the same thing works.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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