You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

20 lines
722 B

  1. from django.conf import settings
  2. from django.contrib.flatpages.views import flatpage
  3. from django.http import Http404
  4. class FlatpageFallbackMiddleware(object):
  5. def process_response(self, request, response):
  6. if response.status_code != 404:
  7. return response # No need to check for a flatpage for non-404 responses.
  8. try:
  9. return flatpage(request, request.path_info)
  10. # Return the original response if any errors happened. Because this
  11. # is a middleware, we can't assume the errors will be caught elsewhere.
  12. except Http404:
  13. return response
  14. except Exception:
  15. if settings.DEBUG:
  16. raise
  17. return response