Ticket #16175: sitemaps-use-templateresponse.diff
File sitemaps-use-templateresponse.diff, 2.2 KB (added by , 13 years ago) |
---|
-
docs/ref/contrib/sitemaps.txt
312 312 'template_name': 'custom_sitemap.html' 313 313 }), 314 314 ) 315 316 .. versionadded:: 1.4 315 317 318 In addition, these views also return :class:`~django.template.response.TemplateResponse` 319 instances which allow you to easily customize the response data before rendering. 320 For more details, see the :doc:`TemplateResponse documentation </ref/template-response>`. 321 316 322 Pinging Google 317 323 ============== 318 324 -
django/contrib/sitemaps/views.py
1 1 from django.http import HttpResponse, Http404 2 from django.template import loader3 2 from django.contrib.sites.models import get_current_site 4 3 from django.core import urlresolvers 5 4 from django.utils.encoding import smart_str 6 5 from django.core.paginator import EmptyPage, PageNotAnInteger 6 from django.template.response import TemplateResponse 7 7 8 8 def index(request, sitemaps, template_name='sitemap_index.xml'): 9 9 current_site = get_current_site(request) … … 20 20 if pages > 1: 21 21 for page in range(2, pages+1): 22 22 sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page)) 23 xml = loader.render_to_string(template_name, {'sitemaps': sites}) 24 return HttpResponse(xml, mimetype='application/xml') 23 return TemplateResponse(request, template_name, {'sitemaps': sites}, mimetype='application/xml') 25 24 26 25 def sitemap(request, sitemaps, section=None, template_name='sitemap.xml'): 27 26 maps, urls = [], [] … … 43 42 raise Http404("Page %s empty" % page) 44 43 except PageNotAnInteger: 45 44 raise Http404("No page '%s'" % page) 46 xml = smart_str(loader.render_to_string(template_name, {'urlset': urls})) 47 return HttpResponse(xml, mimetype='application/xml') 45 return TemplateResponse(request, template_name, {'urlset': urls}, mimetype='application/xml')