Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#15658 closed Bug (invalid)

reverse returns '//' for flatpage with URL '/'

Reported by: Fladi Owned by: Andy Durdin
Component: contrib.flatpages Version: 1.2
Severity: Normal Keywords: flatpages
Cc: me@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using reverse() with a flatpage url '/' results in '//'.

urlpatterns = patterns('',
    (r'^', include('django.contrib.flatpages.urls')),
)
>>> from django.core.urlresolvers import reverse; reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': '/'})
'//'

settings.APPEND_SLASH is False but should not affect this anyways.

Change History (7)

comment:1 by Matthias Kestenholz, 14 years ago

Component: UncategorizedContrib apps
Triage Stage: UnreviewedAccepted

I can confirm this is a real issue.

Btw, this issue is the reason why most CMS applications use two URLconf entries for reversing; in the case of FeinCMS feincms_home (r'$') and feincms_handler (r'(.*)/$')

comment:2 by Gabriel Hurley, 14 years ago

Component: Contrib appscontrib.flatpages

comment:3 by Luke Plant, 14 years ago

Type: Bug

comment:4 by Luke Plant, 14 years ago

Severity: Normal

comment:5 by Andy Durdin, 13 years ago

Easy pickings: unset
Owner: changed from nobody to Andy Durdin
Status: newassigned

comment:6 by Andy Durdin, 13 years ago

Resolution: invalid
Status: assignedclosed

Invalid.

The initial '/' in the path is matched by the root urlresolver, and so is not included in the kwargs of the resolved view nor should it be included in the kwargs when reversing. For example, when '/' resolves to flatpage.views.flatpage, the view is called with the kwarg url=''. Similarly, reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': ''}) returns '/'. This is correct and expected behaviour.

You should be calling reverse() with kwargs={'url': ''}.

comment:7 by Andy Durdin, 13 years ago

Cc: me@… added
Note: See TracTickets for help on using tickets.
Back to Top