Ticket #18351: add_http_tag.diff

File add_http_tag.diff, 1.8 KB (added by mlissner, 3 years ago)

Removed noimageindex, which doesn't make sense in this context.

  • django/contrib/sitemaps/views.py

    diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
    index b90a39e..a8bb374 100644
    a b  
    11from django.contrib.sites.models import get_current_site
    22from django.core import urlresolvers
    33from django.core.paginator import EmptyPage, PageNotAnInteger
    4 from django.http import Http404
    5 from django.template.response import TemplateResponse
     4from django.http import Http404, HttpResponse
     5from django.template import loader
     6from django.utils.encoding import smart_str
     7
    68
    79def index(request, sitemaps,
    810          template_name='sitemap_index.xml', mimetype='application/xml',
    def index(request, sitemaps, 
    2224        for page in range(2, site.paginator.num_pages + 1):
    2325            sites.append('%s?p=%s' % (absolute_url, page))
    2426
    25     return TemplateResponse(request, template_name, {'sitemaps': sites},
    26                             content_type=mimetype)
     27    xml = loader.render_to_string(template_name, {'sitemaps': sites})
     28    response = HttpResponse(xml, mimetype=mimetype)
     29    response['X-Robots-Tag'] = 'noindex, noodp, noarchive'
     30    return response
     31
    2732
    2833def sitemap(request, sitemaps, section=None,
    2934            template_name='sitemap.xml', mimetype='application/xml'):
    def sitemap(request, sitemaps, section=None, 
    4954            raise Http404("Page %s empty" % page)
    5055        except PageNotAnInteger:
    5156            raise Http404("No page '%s'" % page)
    52     return TemplateResponse(request, template_name, {'urlset': urls},
    53                             content_type=mimetype)
     57
     58    xml = smart_str(loader.render_to_string(template_name, {'urlset': urls}))
     59    response = HttpResponse(xml, mimetype=mimetype)
     60    response['X-Robots-Tag'] = 'noindex, noodp, noarchive'
     61    return response
     62
Back to Top