Opened 10 years ago

Closed 10 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: master
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


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

urlpatterns = patterns('',
    (r'', include(''),

with my/app/ having:

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

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

<a href="{% url 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/ 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 Changed 10 years ago by Dan Crosta

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