Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15658 closed Bug (invalid)

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

Reported by: Fladi Owned by: adurdin
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:


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 5 years ago by mk

  • Component changed from Uncategorized to Contrib apps
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 5 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.flatpages

comment:3 Changed 5 years ago by lukeplant

  • Type set to Bug

comment:4 Changed 5 years ago by lukeplant

  • Severity set to Normal

comment:5 Changed 5 years ago by adurdin

  • Easy pickings unset
  • Owner changed from nobody to adurdin
  • Status changed from new to assigned

comment:6 Changed 5 years ago by adurdin

  • Resolution set to invalid
  • Status changed from assigned to closed


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 5 years ago by adurdin

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