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
- "Magic Link" Management Command by webology 2 months, 3 weeks ago
- Closest ORM models to a latitude/longitude point by simonw 2 months, 3 weeks ago
- Log the time taken to execute each DB query by kennyx46 2 months, 3 weeks ago
- django database snippet by ItsRLuo 2 months, 4 weeks ago
- Serialize a model instance by chriswedgwood 3 months, 3 weeks ago