Opened 10 years ago

Closed 4 years ago

#22261 closed Bug (fixed)

reverse() and get_absolute_url() may return different values for same FlatPage

Reported by: allo@… Owned by: Hasan Ramezani
Component: contrib.flatpages Version: 1.6
Severity: Normal Keywords:
Cc: edanm Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

The FlatPage model implements get_absolute_url() without using reverse(). The comment suggests, that this handles SCRIPT_NAME issues, but the link in the admin interface does not work, if you are using a prefix for the flatpages urls. The templatetag for resolving a flatpage works just fine.

Change History (9)

comment:1 Changed 10 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

The implementation is intended to match the catchall middleware.

We could try reversing and only if that fails fall back to the current logic.

comment:2 Changed 10 years ago by edanm

Owner: changed from nobody to edanm
Status: newassigned

comment:3 Changed 10 years ago by edanm

Has patch: set

I just sent a pull request for a fix for this:
https://github.com/django/django/pull/2554

This solves all the cases I can think of for including flatpages and running get_absolute_url() on them.

By the way, not sure if this is relevant, but:
When I was writing the tests for this, I noticed that all the flatpages tests include the flatpages url without a slash, e.g.:
url(r'flatpage_root', include('django.contrib.flatpages.urls')), (Note lack of '/' after flatpage_root).

This is different than how the documentation recommends including the flatpages, and doesn't make much sense. Not sure what the purpose of this is.

Last edited 10 years ago by edanm (previous) (diff)

comment:4 Changed 10 years ago by edanm

Cc: edanm added

comment:5 Changed 9 years ago by Tim Graham

Patch needs improvement: set

I left comments for improvement on the PR. Please uncheck "Patch needs improvement" when you update it, thanks.

comment:6 Changed 6 years ago by Tim Graham

Description: modified (diff)
Summary: Wrong Permalink for flatpagesreverse() and get_absolute_url() may return different values for same FlatPage

#28118 is a duplicate.

comment:7 Changed 4 years ago by Hasan Ramezani

Owner: changed from edanm to Hasan Ramezani
Patch needs improvement: unset

I created another PR based on the first PR.

comment:8 Changed 4 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In e2fab0b:

Refs #22261 -- Added missing trailing slash to the flatpages_tests urls.

comment:9 Changed 4 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 2633c534:

Fixed #22261 -- Fixed resolving namespaced URLs for flatpages.

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