Login

FlatPageOverrideMiddleware

Author:
David
Posted:
November 28, 2008
Language:
Python
Version:
1.0
Score:
0 (after 0 ratings)

This snippet is a piece of middleware that can be used to allow an administrator to create a flatpage that will override an existing URL.

Why would you want such a thing? Maybe an admin needs to be able to override individual detail pages of an item list at will and doesn't want to be bothered mucking around with urlconf and restarting apache2.

Obviously, it's not the ideal situation for permanent overrides (in that case, you'd be better off writing an exception in the urlconf), but it's good for the temporary, one-off, situations that may arise for whatever reasons.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    from django.contrib.flatpages.views import flatpage
    from django.http import Http404
    from django.conf import settings

    class FlatpageOverrideMiddleware(object):
        def process_request(self, request):
            try:
                return flatpage(request, request.path)
            except Http404:
                return None
            except:
                if settings.DEBUG:
                    raise
                return response

More like this

  1. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 2 months, 3 weeks ago
  2. Python Django CRUD Example Tutorial by tuts_station 3 months ago
  3. Browser-native date input field by kytta 4 months, 3 weeks ago
  4. Generate and render HTML Table by LLyaudet 5 months ago
  5. My firs Snippets by GutemaG 5 months ago

Comments

Please login first before commenting.