Opened 8 years ago

Closed 8 years ago

Last modified 8 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


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 Changed 8 years ago by Matthias Kestenholz

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 Changed 8 years ago by Gabriel Hurley

Component: Contrib appscontrib.flatpages

comment:3 Changed 8 years ago by Luke Plant

Type: Bug

comment:4 Changed 8 years ago by Luke Plant

Severity: Normal

comment:5 Changed 8 years ago by Andy Durdin

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

comment:6 Changed 8 years ago by Andy Durdin

Resolution: invalid
Status: assignedclosed


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 Changed 8 years ago by Andy Durdin

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