- November 28, 2008
- flatpage override
- 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