Added USE_FLAT_PAGES setting, which defaults to True.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@782 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
16f9b08611
commit
c3fa47edb8
|
@ -100,6 +100,9 @@ ALLOWED_INCLUDE_ROOTS = ()
|
||||||
# is an admin.
|
# is an admin.
|
||||||
ADMIN_FOR = []
|
ADMIN_FOR = []
|
||||||
|
|
||||||
|
# Whether to check the flat-pages table as a last resort for all 404 errors.
|
||||||
|
USE_FLAT_PAGES = True
|
||||||
|
|
||||||
# 404s that may be ignored.
|
# 404s that may be ignored.
|
||||||
IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
|
IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
|
||||||
IGNORABLE_404_ENDS = ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')
|
IGNORABLE_404_ENDS = ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')
|
||||||
|
|
|
@ -54,29 +54,27 @@ class CommonMiddleware:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
"""
|
"Check for a flat page (for 404s) and calculate the Etag, if needed."
|
||||||
Check for a flatfile (for 404s) and calculate the Etag, if needed.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# If this was a 404, check for a flat file
|
|
||||||
if response.status_code == 404:
|
if response.status_code == 404:
|
||||||
try:
|
if settings.USE_FLAT_PAGES:
|
||||||
response = flat_file(request, request.path)
|
try:
|
||||||
except exceptions.Http404:
|
return flat_file(request, request.path)
|
||||||
|
except exceptions.Http404:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if settings.SEND_BROKEN_LINK_EMAILS:
|
||||||
# If the referrer was from an internal link or a non-search-engine site,
|
# If the referrer was from an internal link or a non-search-engine site,
|
||||||
# send a note to the managers.
|
# send a note to the managers.
|
||||||
if settings.SEND_BROKEN_LINK_EMAILS:
|
domain = request.META['HTTP_HOST']
|
||||||
domain = request.META['HTTP_HOST']
|
referer = request.META.get('HTTP_REFERER', None)
|
||||||
referer = request.META.get('HTTP_REFERER', None)
|
is_internal = referer and (domain in referer)
|
||||||
is_internal = referer and (domain in referer)
|
path = request.get_full_path()
|
||||||
path = request.get_full_path()
|
if referer and not _is_ignorable_404(path) and (is_internal or '?' not in referer):
|
||||||
if referer and not _is_ignorable_404(path) and (is_internal or '?' not in referer):
|
mail_managers("Broken %slink on %s" % ((is_internal and 'INTERNAL ' or ''), domain),
|
||||||
mail_managers("Broken %slink on %s" % ((is_internal and 'INTERNAL ' or ''), domain),
|
"Referrer: %s\nRequested URL: %s\n" % (referer, request.get_full_path()))
|
||||||
"Referrer: %s\nRequested URL: %s\n" % (referer, request.get_full_path()))
|
|
||||||
# If there's no flatfile we want to return the original 404 response
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# Use ETags, if requested
|
# Use ETags, if requested.
|
||||||
if settings.USE_ETAGS:
|
if settings.USE_ETAGS:
|
||||||
etag = md5.new(response.get_content_as_string('utf-8')).hexdigest()
|
etag = md5.new(response.get_content_as_string('utf-8')).hexdigest()
|
||||||
if request.META.get('HTTP_IF_NONE_MATCH') == etag:
|
if request.META.get('HTTP_IF_NONE_MATCH') == etag:
|
||||||
|
|
Loading…
Reference in New Issue