Opened 10 years ago

Last modified 4 years ago

#22261 closed Bug

reverse() and get_absolute_url() may return different values for same FlatPage — at Version 6

Reported by: allo@… Owned by: edanm
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 (6)

comment:1 by Aymeric Augustin, 10 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, 10 years ago

Owner: changed from nobody to edanm
Status: newassigned

comment:3 by edanm, 10 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 10 years ago by edanm (previous) (diff)

comment:4 by edanm, 10 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.

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