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