Skip to content
Browse files

Fixed #12347 -- Added a mimetype option to sitemaps views to further …

…customize the output of the view, e.g. to support Yahoo's plain text urllist format. Thanks, afurlan.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 3fe0c69 commit 60f0421ed3ea16ba78545eeabcde7a3dcdcb7cdd @jezdez jezdez committed
Showing with 6 additions and 4 deletions.
  1. +6 −4 django/contrib/sitemaps/
10 django/contrib/sitemaps/
@@ -5,7 +5,8 @@
from django.utils.encoding import smart_str
from django.core.paginator import EmptyPage, PageNotAnInteger
-def index(request, sitemaps, template_name='sitemap_index.xml'):
+def index(request, sitemaps,
+ template_name='sitemap_index.xml', mimetype='application/xml'):
current_site = get_current_site(request)
sites = []
protocol = request.is_secure() and 'https' or 'http'
@@ -21,9 +22,10 @@ def index(request, sitemaps, template_name='sitemap_index.xml'):
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='application/xml')
+ return HttpResponse(xml, mimetype=mimetype)
-def sitemap(request, sitemaps, section=None, template_name='sitemap.xml'):
+def sitemap(request, sitemaps, section=None,
+ template_name='sitemap.xml', mimetype='application/xml'):
maps, urls = [], []
if section is not None:
if section not in sitemaps:
@@ -43,4 +45,4 @@ def sitemap(request, sitemaps, section=None, template_name='sitemap.xml'):
except PageNotAnInteger:
raise Http404("No page '%s'" % page)
xml = smart_str(loader.render_to_string(template_name, {'urlset': urls}))
- return HttpResponse(xml, mimetype='application/xml')
+ return HttpResponse(xml, mimetype=mimetype)

0 comments on commit 60f0421

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