Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18351 -- Added X-Robots-Tag header to sitemaps

Thanks Michael Lissner for the report and initial patch, and
Tom Mortimer-Jones for working on the patch.
  • Loading branch information...
commit 66c83dce074b48342dbfd0d9039c76b8949f0833 1 parent ac9daa0
@claudep claudep authored
View
7 django/contrib/sitemaps/tests/test_http.py
@@ -144,3 +144,10 @@ def test_cached_sitemap_index(self):
</sitemapindex>
""" % self.base_url
self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
+
+ def test_x_robots_sitemap(self):
+ response = self.client.get('/simple/index.xml')
+ self.assertEqual(response['X-Robots-Tag'], 'noindex, noodp, noarchive')
+
+ response = self.client.get('/simple/sitemap.xml')
+ self.assertEqual(response['X-Robots-Tag'], 'noindex, noodp, noarchive')
View
11 django/contrib/sitemaps/views.py
@@ -6,7 +6,17 @@
from django.http import Http404
from django.template.response import TemplateResponse
from django.utils import six
+from django.utils.functional import wraps
+def x_robots_tag(func):
+ @wraps(func)
+ def inner(request, *args, **kwargs):
+ response = func(request, *args, **kwargs)
+ response['X-Robots-Tag'] = 'noindex, noodp, noarchive'
+ return response
+ return inner
+
+@x_robots_tag
def index(request, sitemaps,
template_name='sitemap_index.xml', content_type='application/xml',
sitemap_url_name='django.contrib.sitemaps.views.sitemap',
@@ -35,6 +45,7 @@ def index(request, sitemaps,
return TemplateResponse(request, template_name, {'sitemaps': sites},
content_type=content_type)
+@x_robots_tag
def sitemap(request, sitemaps, section=None,
template_name='sitemap.xml', content_type='application/xml',
mimetype=None):
Please sign in to comment.
Something went wrong with that request. Please try again.