Opened 16 years ago

Closed 16 years ago

#8051 closed (invalid)

urlresolvers.reverse assumes that top-level URL mappings are not empty

Reported by: Dan Crosta Owned by: nobody
Component: Uncategorized Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If I want to map a certain application's URLs as the default handler, with a urlconf like so:

urlpatterns = patterns('',
    (r'', include('my.app.urls'),
)

with my/app/urls.py having:

urlpatterns = patterns('my.app.views',
    (r'(?P<full_url>.*)', 'show_page'),
)

Then when I use the {% url ... %} template tag, I get wrong URLs. If I write:

<a href="{% url my.app.views.show_page another_page.full_url %}">{{another_page.title}}</a>

I expect to get:

<a href="/full_url_to_another_page">Another Page</a>

But instead get:

<a href="'''//'''full_url_to_another_page">Another Page</a>

Those two leading slashes break the link -- Firefox 3 at least is interpereting it as a fully-qualified URL (with an implicit "http:" in the front, I guess?)

I tracked this down to [browser:django/trunk/django/core/urlresolvers.py@8015#L315 urlresolvers.py line 315] which adds a "/" to the prefix, even if the prefix is explicitly set to None or the empty string. I would add a patch, except I don't know Django core well enough to even hypothesize what it would look like.

Change History (1)

comment:1 by Dan Crosta, 16 years ago

Resolution: invalid
Status: newclosed

In retrospect, it looks like I was using {% url ... %} wrong (the argument I was passing had a leading slash in it). I'm closing this out.

Note: See TracTickets for help on using tickets.
Back to Top