Fixed #6213 -- Updated the flatpages app to only append a slash if the flatpage actually exist.

The FlatpageFallbackMiddleware (and the view) now only add a trailing slash and redirect if the resulting URL refers to an existing flatpage. Previously requesting /notaflatpageoravalidurl would redirect to /notaflatpageoravalidurl/, which would then raise a 404. Requesting /notaflatpageoravalidurl now will immediately raise a 404. Also, Redirects returned by flatpages are now permanent (301 status code) to match the behaviour of the CommonMiddleware.

Thanks to Steve Losh for the initial work on the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16048 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-04-20 14:41:47 +00:00
parent 96520e87bd
commit 196ac8f8b3
5 changed files with 195 additions and 5 deletions

View file

@ -77,6 +77,18 @@ does all of the work.
:class:`~django.template.RequestContext` in rendering the
template.
.. versionchanged:: 1.4
The middleware will only add a trailing slash and redirect (by looking
at the :setting:`APPEND_SLASH` setting) if the resulting URL refers to
a valid flatpage. Previously requesting a non-existent flatpage
would redirect to the same URL with an apppended slash first and
subsequently raise a 404.
.. versionchanged:: 1.4
Redirects by the middlware are permanent (301 status code) instead of
temporary (302) to match behaviour of the
:class:`~django.middleware.common.CommonMiddleware`.
If it doesn't find a match, the request continues to be processed as usual.
The middleware only gets activated for 404s -- not for 500s or responses

View file

@ -78,3 +78,16 @@ Django instance, and try to submit it to the upgraded Django instance:
* time period: the amount of time you expect user to take filling out
such forms.
django.contrib.flatpages
~~~~~~~~~~~~~~~~~~~~~~~~
Starting in the 1.4 release the
:class:`~django.contrib.flatpages.middleware.FlatpageFallbackMiddleware` only
adds a trailing slash and redirects if the resulting URL refers to an existing
flatpage. For example, requesting ``/notaflatpageoravalidurl`` in a previous
version would redirect to ``/notaflatpageoravalidurl/``, which would
subsequently raise a 404. Requesting ``/notaflatpageoravalidurl`` now will
immediately raise a 404. Additionally redirects returned by flatpages are now
permanent (301 status code) to match the behaviour of the
:class:`~django.middleware.common.CommonMiddleware`.