summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2011-05-05 20:49:26 +0000
committerLuke Plant <L.Plant.98@cantab.net>2011-05-05 20:49:26 +0000
commit171df93170df23d2fea1f8320ddb80c6f6444ff7 (patch)
treeba9ccc91915ff2d3f76a45994d5f49f4df7d6bce /django
parentdb5807bdb1f242cc928e2fdf7110cb20af34790f (diff)
Fixed #15954 - New IGNORABLE_404_URLS setting that allows more powerful filtering of 404s to ignore
Thanks to aaugustin for implementing this. (Technically this doesn't fix the original report, as we've decided against having *any* default values, but the new feature makes it possible, and the docs have an example addressing #15954). git-svn-id: http://code.djangoproject.com/svn/django/trunk@16160 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/conf/global_settings.py14
-rw-r--r--django/middleware/common.py24
2 files changed, 28 insertions, 10 deletions
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 1ab9b498a9..477f13b675 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -246,9 +246,17 @@ ALLOWED_INCLUDE_ROOTS = ()
# is an admin.
ADMIN_FOR = ()
-# 404s that may be ignored.
-IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
-IGNORABLE_404_ENDS = ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')
+# List of compiled regular expression objects representing URLs that need not
+# be reported when SEND_BROKEN_LINK_EMAILS is True. Here are a few examples:
+# import re
+# IGNORABLE_404_URLS = (
+# re.compile(r'^/apple-touch-icon.*\.png$'),
+# re.compile(r'^/favicon.ico$),
+# re.compile(r'^/robots.txt$),
+# re.compile(r'^/phpmyadmin/),
+# re.compile(r'\.(cgi|php|pl)$'),
+# )
+IGNORABLE_404_URLS = ()
# A secret key for this particular Django installation. Used in secret-key
# hashing algorithms. Set this in your settings, or Django will complain
diff --git a/django/middleware/common.py b/django/middleware/common.py
index eb145edf19..689929bea4 100644
--- a/django/middleware/common.py
+++ b/django/middleware/common.py
@@ -127,13 +127,23 @@ def _is_ignorable_404(uri):
"""
Returns True if a 404 at the given URL *shouldn't* notify the site managers.
"""
- for start in settings.IGNORABLE_404_STARTS:
- if uri.startswith(start):
- return True
- for end in settings.IGNORABLE_404_ENDS:
- if uri.endswith(end):
- return True
- return False
+ if getattr(settings, 'IGNORABLE_404_STARTS', ()):
+ import warnings
+ warnings.warn('The IGNORABLE_404_STARTS setting has been deprecated '
+ 'in favour of IGNORABLE_404_URLS.',
+ PendingDeprecationWarning)
+ for start in settings.IGNORABLE_404_STARTS:
+ if uri.startswith(start):
+ return True
+ if getattr(settings, 'IGNORABLE_404_ENDS', ()):
+ import warnings
+ warnings.warn('The IGNORABLE_404_ENDS setting has been deprecated '
+ 'in favour of IGNORABLE_404_URLS.',
+ PendingDeprecationWarning)
+ for end in settings.IGNORABLE_404_ENDS:
+ if uri.endswith(end):
+ return True
+ return any(pattern.search(uri) for pattern in settings.IGNORABLE_404_URLS)
def _is_internal_request(domain, referer):
"""