Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16175 -- Modified the sitemaps views to return TemplateRespons…

…e instances for easier customization. Thanks, mat.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16476 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 54552ee29f5e24f6aefead31b7097252490c05f3 1 parent 60f0421
Jannis Leidel authored June 28, 2011
15  django/contrib/sitemaps/views.py
... ...
@@ -1,9 +1,10 @@
1  
-from django.http import HttpResponse, Http404
2  
-from django.template import loader
3  
-from django.contrib.sites.models import get_current_site
4 1
 from django.core import urlresolvers
5  
-from django.utils.encoding import smart_str
6 2
 from django.core.paginator import EmptyPage, PageNotAnInteger
  3
+from django.http import HttpResponse, Http404
  4
+from django.template.response import TemplateResponse
  5
+from django.utils.encoding import smart_str
  6
+
  7
+from django.contrib.sites.models import get_current_site
7 8
 
8 9
 def index(request, sitemaps,
9 10
         template_name='sitemap_index.xml', mimetype='application/xml'):
@@ -21,8 +22,7 @@ def index(request, sitemaps,
21 22
         if pages > 1:
22 23
             for page in range(2, pages+1):
23 24
                 sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
24  
-    xml = loader.render_to_string(template_name, {'sitemaps': sites})
25  
-    return HttpResponse(xml, mimetype=mimetype)
  25
+    return TemplateResponse(request, template_name, {'sitemaps': sites}, mimetype=mimetype)
26 26
 
27 27
 def sitemap(request, sitemaps, section=None,
28 28
         template_name='sitemap.xml', mimetype='application/xml'):
@@ -44,5 +44,4 @@ def sitemap(request, sitemaps, section=None,
44 44
             raise Http404("Page %s empty" % page)
45 45
         except PageNotAnInteger:
46 46
             raise Http404("No page '%s'" % page)
47  
-    xml = smart_str(loader.render_to_string(template_name, {'urlset': urls}))
48  
-    return HttpResponse(xml, mimetype=mimetype)
  47
+    return TemplateResponse(request, template_name, {'urlset': urls}, mimetype=mimetype)
9  docs/ref/contrib/sitemaps.txt
@@ -313,6 +313,15 @@ parameter to the ``sitemap`` and ``index`` views via the URLconf::
313 313
         }),
314 314
     )
315 315
 
  316
+
  317
+.. versionchanged:: 1.4
  318
+
  319
+    In addition, these views also return
  320
+    :class:`~django.template.response.TemplateResponse`
  321
+    instances which allow you to easily customize the response data before
  322
+    rendering. For more details, see the
  323
+    :doc:`TemplateResponse documentation </ref/template-response>`.
  324
+
316 325
 Context variables
317 326
 ------------------
318 327
 

0 notes on commit 54552ee

Please sign in to comment.
Something went wrong with that request. Please try again.