Converted some of the built-in views to use content_type instead of mimetype HttpResponse argument. Refs #16519
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d3055b3382
commit
8767439af4
|
@ -20,7 +20,7 @@ def compress_kml(kml):
|
||||||
def render_to_kml(*args, **kwargs):
|
def render_to_kml(*args, **kwargs):
|
||||||
"Renders the response as KML (using the correct MIME type)."
|
"Renders the response as KML (using the correct MIME type)."
|
||||||
return HttpResponse(loader.render_to_string(*args, **kwargs),
|
return HttpResponse(loader.render_to_string(*args, **kwargs),
|
||||||
mimetype='application/vnd.google-earth.kml+xml')
|
content_type='application/vnd.google-earth.kml+xml')
|
||||||
|
|
||||||
def render_to_kmz(*args, **kwargs):
|
def render_to_kmz(*args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -28,10 +28,9 @@ def render_to_kmz(*args, **kwargs):
|
||||||
MIME type).
|
MIME type).
|
||||||
"""
|
"""
|
||||||
return HttpResponse(compress_kml(loader.render_to_string(*args, **kwargs)),
|
return HttpResponse(compress_kml(loader.render_to_string(*args, **kwargs)),
|
||||||
mimetype='application/vnd.google-earth.kmz')
|
content_type='application/vnd.google-earth.kmz')
|
||||||
|
|
||||||
|
|
||||||
def render_to_text(*args, **kwargs):
|
def render_to_text(*args, **kwargs):
|
||||||
"Renders the response using the MIME type for plain text."
|
"Renders the response using the MIME type for plain text."
|
||||||
return HttpResponse(loader.render_to_string(*args, **kwargs),
|
return HttpResponse(loader.render_to_string(*args, **kwargs),
|
||||||
mimetype='text/plain')
|
content_type='text/plain')
|
||||||
|
|
|
@ -30,7 +30,7 @@ def index(request, sitemaps):
|
||||||
for page in range(2, pages+1):
|
for page in range(2, pages+1):
|
||||||
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
|
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
|
||||||
xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
|
xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
|
||||||
return HttpResponse(xml, mimetype='application/xml')
|
return HttpResponse(xml, content_type='application/xml')
|
||||||
|
|
||||||
def sitemap(request, sitemaps, section=None):
|
def sitemap(request, sitemaps, section=None):
|
||||||
"""
|
"""
|
||||||
|
@ -58,7 +58,7 @@ def sitemap(request, sitemaps, section=None):
|
||||||
except PageNotAnInteger:
|
except PageNotAnInteger:
|
||||||
raise Http404("No page '%s'" % page)
|
raise Http404("No page '%s'" % page)
|
||||||
xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
|
xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
|
||||||
return HttpResponse(xml, mimetype='application/xml')
|
return HttpResponse(xml, content_type='application/xml')
|
||||||
|
|
||||||
def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
|
def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
|
from django.contrib.sites.models import get_current_site
|
||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
from django.core.paginator import EmptyPage, PageNotAnInteger
|
from django.core.paginator import EmptyPage, PageNotAnInteger
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
|
||||||
from django.contrib.sites.models import get_current_site
|
def index(request, sitemaps, template_name='sitemap_index.xml', mimetype='application/xml'):
|
||||||
|
|
||||||
def index(request, sitemaps,
|
|
||||||
template_name='sitemap_index.xml', mimetype='application/xml'):
|
|
||||||
current_site = get_current_site(request)
|
current_site = get_current_site(request)
|
||||||
sites = []
|
sites = []
|
||||||
protocol = request.is_secure() and 'https' or 'http'
|
protocol = request.is_secure() and 'https' or 'http'
|
||||||
|
@ -21,10 +19,9 @@ def index(request, sitemaps,
|
||||||
if pages > 1:
|
if pages > 1:
|
||||||
for page in range(2, pages+1):
|
for page in range(2, pages+1):
|
||||||
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
|
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
|
||||||
return TemplateResponse(request, template_name, {'sitemaps': sites}, mimetype=mimetype)
|
return TemplateResponse(request, template_name, {'sitemaps': sites}, content_type=mimetype)
|
||||||
|
|
||||||
def sitemap(request, sitemaps, section=None,
|
def sitemap(request, sitemaps, section=None, template_name='sitemap.xml', mimetype='application/xml'):
|
||||||
template_name='sitemap.xml', mimetype='application/xml'):
|
|
||||||
maps, urls = [], []
|
maps, urls = [], []
|
||||||
if section is not None:
|
if section is not None:
|
||||||
if section not in sitemaps:
|
if section not in sitemaps:
|
||||||
|
@ -43,4 +40,4 @@ def sitemap(request, sitemaps, section=None,
|
||||||
raise Http404("Page %s empty" % page)
|
raise Http404("Page %s empty" % page)
|
||||||
except PageNotAnInteger:
|
except PageNotAnInteger:
|
||||||
raise Http404("No page '%s'" % page)
|
raise Http404("No page '%s'" % page)
|
||||||
return TemplateResponse(request, template_name, {'urlset': urls}, mimetype=mimetype)
|
return TemplateResponse(request, template_name, {'urlset': urls}, content_type=mimetype)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Feed(object):
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
raise Http404('Feed object does not exist.')
|
raise Http404('Feed object does not exist.')
|
||||||
feedgen = self.get_feed(obj, request)
|
feedgen = self.get_feed(obj, request)
|
||||||
response = HttpResponse(mimetype=feedgen.mime_type)
|
response = HttpResponse(content_type=feedgen.mime_type)
|
||||||
feedgen.write(response, 'utf-8')
|
feedgen.write(response, 'utf-8')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ def direct_to_template(request, template, extra_context=None, mimetype=None, **k
|
||||||
dictionary[key] = value
|
dictionary[key] = value
|
||||||
c = RequestContext(request, dictionary)
|
c = RequestContext(request, dictionary)
|
||||||
t = loader.get_template(template)
|
t = loader.get_template(template)
|
||||||
return HttpResponse(t.render(c), mimetype=mimetype)
|
return HttpResponse(t.render(c), content_type=mimetype)
|
||||||
|
|
||||||
def redirect_to(request, url, permanent=True, query_string=False, **kwargs):
|
def redirect_to(request, url, permanent=True, query_string=False, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -538,7 +538,7 @@ Typical usage is to pass the contents of the page, as a string, to the
|
||||||
|
|
||||||
>>> from django.http import HttpResponse
|
>>> from django.http import HttpResponse
|
||||||
>>> response = HttpResponse("Here's the text of the Web page.")
|
>>> response = HttpResponse("Here's the text of the Web page.")
|
||||||
>>> response = HttpResponse("Text only, please.", mimetype="text/plain")
|
>>> response = HttpResponse("Text only, please.", content_type="text/plain")
|
||||||
|
|
||||||
But if you want to add content incrementally, you can use ``response`` as a
|
But if you want to add content incrementally, you can use ``response`` as a
|
||||||
file-like object::
|
file-like object::
|
||||||
|
@ -577,10 +577,10 @@ Telling the browser to treat the response as a file attachment
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
To tell the browser to treat the response as a file attachment, use the
|
To tell the browser to treat the response as a file attachment, use the
|
||||||
``mimetype`` argument and set the ``Content-Disposition`` header. For example,
|
``content_type`` argument and set the ``Content-Disposition`` header. For example,
|
||||||
this is how you might return a Microsoft Excel spreadsheet::
|
this is how you might return a Microsoft Excel spreadsheet::
|
||||||
|
|
||||||
>>> response = HttpResponse(my_data, mimetype='application/vnd.ms-excel')
|
>>> response = HttpResponse(my_data, content_type='application/vnd.ms-excel')
|
||||||
>>> response['Content-Disposition'] = 'attachment; filename=foo.xls'
|
>>> response['Content-Disposition'] = 'attachment; filename=foo.xls'
|
||||||
|
|
||||||
There's nothing Django-specific about the ``Content-Disposition`` header, but
|
There's nothing Django-specific about the ``Content-Disposition`` header, but
|
||||||
|
|
Loading…
Reference in New Issue