mirror of
https://github.com/django/django.git
synced 2025-03-13 10:50:55 +00:00
serving data in the flatpage middleware. Patch from jcassee. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8457 bcc190cf-cafb-0310-a4f2-bffc1f526a37
19 lines
710 B
Python
19 lines
710 B
Python
from django.contrib.flatpages.views import flatpage
|
|
from django.http import Http404
|
|
from django.conf import settings
|
|
|
|
class FlatpageFallbackMiddleware(object):
|
|
def process_response(self, request, response):
|
|
if response.status_code != 404:
|
|
return response # No need to check for a flatpage for non-404 responses.
|
|
try:
|
|
return flatpage(request, request.path_info)
|
|
# Return the original response if any errors happened. Because this
|
|
# is a middleware, we can't assume the errors will be caught elsewhere.
|
|
except Http404:
|
|
return response
|
|
except:
|
|
if settings.DEBUG:
|
|
raise
|
|
return response
|