summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-06-28 10:17:01 +0000
committerJannis Leidel <jannis@leidel.info>2011-06-28 10:17:01 +0000
commit54552ee29f5e24f6aefead31b7097252490c05f3 (patch)
tree7a6f57f048e45b9a4c53cf8f02a5c3544d1d826d
parent60f0421ed3ea16ba78545eeabcde7a3dcdcb7cdd (diff)
Fixed #16175 -- Modified the sitemaps views to return TemplateResponse instances for easier customization. Thanks, mat.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16476 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/sitemaps/views.py15
-rw-r--r--docs/ref/contrib/sitemaps.txt9
2 files changed, 16 insertions, 8 deletions
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index 2255587a9e..b117b33aab 100644
--- a/django/contrib/sitemaps/views.py
+++ b/django/contrib/sitemaps/views.py
@@ -1,9 +1,10 @@
-from django.http import HttpResponse, Http404
-from django.template import loader
-from django.contrib.sites.models import get_current_site
from django.core import urlresolvers
-from django.utils.encoding import smart_str
from django.core.paginator import EmptyPage, PageNotAnInteger
+from django.http import HttpResponse, Http404
+from django.template.response import TemplateResponse
+from django.utils.encoding import smart_str
+
+from django.contrib.sites.models import get_current_site
def index(request, sitemaps,
template_name='sitemap_index.xml', mimetype='application/xml'):
@@ -21,8 +22,7 @@ def index(request, sitemaps,
if pages > 1:
for page in range(2, pages+1):
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
- xml = loader.render_to_string(template_name, {'sitemaps': sites})
- return HttpResponse(xml, mimetype=mimetype)
+ return TemplateResponse(request, template_name, {'sitemaps': sites}, mimetype=mimetype)
def sitemap(request, sitemaps, section=None,
template_name='sitemap.xml', mimetype='application/xml'):
@@ -44,5 +44,4 @@ def sitemap(request, sitemaps, section=None,
raise Http404("Page %s empty" % page)
except PageNotAnInteger:
raise Http404("No page '%s'" % page)
- xml = smart_str(loader.render_to_string(template_name, {'urlset': urls}))
- return HttpResponse(xml, mimetype=mimetype)
+ return TemplateResponse(request, template_name, {'urlset': urls}, mimetype=mimetype) \ No newline at end of file
diff --git a/docs/ref/contrib/sitemaps.txt b/docs/ref/contrib/sitemaps.txt
index 6d8fe61f35..300c142f0b 100644
--- a/docs/ref/contrib/sitemaps.txt
+++ b/docs/ref/contrib/sitemaps.txt
@@ -313,6 +313,15 @@ parameter to the ``sitemap`` and ``index`` views via the URLconf::
}),
)
+
+.. versionchanged:: 1.4
+
+ In addition, these views also return
+ :class:`~django.template.response.TemplateResponse`
+ instances which allow you to easily customize the response data before
+ rendering. For more details, see the
+ :doc:`TemplateResponse documentation </ref/template-response>`.
+
Context variables
------------------