Opened 11 years ago

Closed 5 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 by Aymeric Augustin, 11 years ago

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 by edanm, 11 years ago

Owner: changed from nobody to edanm
Status: newassigned

comment:3 by edanm, 11 years ago

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 11 years ago by edanm (previous) (diff)

comment:4 by edanm, 11 years ago

Cc: edanm added

comment:5 by Tim Graham, 10 years ago

Patch needs improvement: set

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

comment:6 by Tim Graham, 7 years ago

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 by Hasan Ramezani, 5 years ago

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

I created another PR based on the first PR.

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In e2fab0b:

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

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

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