diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index cfe3aa6..c8d2f4d 100644
a
|
b
|
|
| 1 | import warnings |
| 2 | |
1 | 3 | from django.contrib.sites.models import get_current_site |
2 | 4 | from django.core import urlresolvers |
3 | 5 | from django.core.paginator import EmptyPage, PageNotAnInteger |
… |
… |
from django.template.response import TemplateResponse
|
6 | 8 | from django.utils import six |
7 | 9 | |
8 | 10 | def index(request, sitemaps, |
9 | | template_name='sitemap_index.xml', mimetype='application/xml', |
10 | | sitemap_url_name='django.contrib.sitemaps.views.sitemap'): |
| 11 | template_name='sitemap_index.xml', content_type='application/xml', |
| 12 | sitemap_url_name='django.contrib.sitemaps.views.sitemap', |
| 13 | mimetype=None): |
| 14 | |
| 15 | if mimetype: |
| 16 | warnings.warn("The mimetype keyword argument is deprecated, use " |
| 17 | "content_type instead", DeprecationWarning, stacklevel=2) |
| 18 | content_type = mimetype |
| 19 | |
11 | 20 | req_protocol = 'https' if request.is_secure() else 'http' |
12 | 21 | req_site = get_current_site(request) |
13 | 22 | |
… |
… |
def index(request, sitemaps,
|
24 | 33 | sites.append('%s?p=%s' % (absolute_url, page)) |
25 | 34 | |
26 | 35 | return TemplateResponse(request, template_name, {'sitemaps': sites}, |
27 | | content_type=mimetype) |
| 36 | content_type=content_type) |
28 | 37 | |
29 | 38 | def sitemap(request, sitemaps, section=None, |
30 | | template_name='sitemap.xml', mimetype='application/xml'): |
| 39 | template_name='sitemap.xml', content_type='application/xml', |
| 40 | mimetype=None): |
| 41 | |
| 42 | if mimetype: |
| 43 | warnings.warn("The mimetype keyword argument is deprecated, use " |
| 44 | "content_type instead", DeprecationWarning, stacklevel=2) |
| 45 | content_type = mimetype |
| 46 | |
31 | 47 | req_protocol = 'https' if request.is_secure() else 'http' |
32 | 48 | req_site = get_current_site(request) |
33 | 49 | |
… |
… |
def sitemap(request, sitemaps, section=None,
|
51 | 67 | except PageNotAnInteger: |
52 | 68 | raise Http404("No page '%s'" % page) |
53 | 69 | return TemplateResponse(request, template_name, {'urlset': urls}, |
54 | | content_type=mimetype) |
| 70 | content_type=content_type) |
diff --git a/django/shortcuts/__init__.py b/django/shortcuts/__init__.py
index 9f89634..21bd7a0 100644
a
|
b
|
This module collects helper functions and classes that "span" multiple levels
|
3 | 3 | of MVC. In other words, these functions/classes introduce controlled coupling |
4 | 4 | for convenience's sake. |
5 | 5 | """ |
| 6 | import warnings |
6 | 7 | |
7 | 8 | from django.template import loader, RequestContext |
8 | 9 | from django.http import HttpResponse, Http404 |
… |
… |
def render_to_response(*args, **kwargs):
|
17 | 18 | Returns a HttpResponse whose content is filled with the result of calling |
18 | 19 | django.template.loader.render_to_string() with the passed arguments. |
19 | 20 | """ |
20 | | httpresponse_kwargs = {'content_type': kwargs.pop('mimetype', None)} |
| 21 | httpresponse_kwargs = {'content_type': kwargs.pop('content_type', None)} |
| 22 | |
| 23 | mimetype = kwargs.pop('mimetype', None) |
| 24 | if mimetype: |
| 25 | warnings.warn("The mimetype keyword argument is deprecated, use " |
| 26 | "content_type instead", DeprecationWarning, stacklevel=2) |
| 27 | httpresponse_kwargs['content_type'] = mimetype |
| 28 | |
21 | 29 | return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) |
22 | 30 | |
23 | 31 | def render(request, *args, **kwargs): |
diff --git a/docs/howto/outputting-csv.txt b/docs/howto/outputting-csv.txt
index bcc6f38..1f9efb5 100644
a
|
b
|
Here's an example::
|
20 | 20 | |
21 | 21 | def some_view(request): |
22 | 22 | # Create the HttpResponse object with the appropriate CSV header. |
23 | | response = HttpResponse(mimetype='text/csv') |
| 23 | response = HttpResponse(content_type='text/csv') |
24 | 24 | response['Content-Disposition'] = 'attachment; filename="somefilename.csv"' |
25 | 25 | |
26 | 26 | writer = csv.writer(response) |
… |
… |
Here's an example, which generates the same CSV file as above::
|
92 | 92 | |
93 | 93 | def some_view(request): |
94 | 94 | # Create the HttpResponse object with the appropriate CSV header. |
95 | | response = HttpResponse(mimetype='text/csv') |
| 95 | response = HttpResponse(content_type='text/csv') |
96 | 96 | response['Content-Disposition'] = 'attachment; filename="somefilename.csv"' |
97 | 97 | |
98 | 98 | # The data is hard-coded here, but you could load it from a database or |
… |
… |
Here's an example, which generates the same CSV file as above::
|
111 | 111 | |
112 | 112 | The only difference between this example and the previous example is that this |
113 | 113 | one uses template loading instead of the CSV module. The rest of the code -- |
114 | | such as the ``mimetype='text/csv'`` -- is the same. |
| 114 | such as the ``content_type='text/csv'`` -- is the same. |
115 | 115 | |
116 | 116 | Then, create the template ``my_template_name.txt``, with this template code: |
117 | 117 | |
diff --git a/docs/howto/outputting-pdf.txt b/docs/howto/outputting-pdf.txt
index 9d87b97..d15f94f 100644
a
|
b
|
Here's a "Hello World" example::
|
51 | 51 | |
52 | 52 | def some_view(request): |
53 | 53 | # Create the HttpResponse object with the appropriate PDF headers. |
54 | | response = HttpResponse(mimetype='application/pdf') |
| 54 | response = HttpResponse(content_type='application/pdf') |
55 | 55 | response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"' |
56 | 56 | |
57 | 57 | # Create the PDF object, using the response object as its "file." |
… |
… |
Here's the above "Hello World" example rewritten to use :mod:`io`::
|
120 | 120 | |
121 | 121 | def some_view(request): |
122 | 122 | # Create the HttpResponse object with the appropriate PDF headers. |
123 | | response = HttpResponse(mimetype='application/pdf') |
| 123 | response = HttpResponse(content_type='application/pdf') |
124 | 124 | response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"' |
125 | 125 | |
126 | 126 | buffer = BytesIO() |
diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt
index 63d65d1..da0d1e2 100644
a
|
b
|
these changes.
|
290 | 290 | specified as a plain string instead of a tuple will be removed and raise an |
291 | 291 | exception. |
292 | 292 | |
293 | | * The ``mimetype`` argument to :class:`~django.http.HttpResponse` ``__init__`` |
294 | | will be removed (``content_type`` should be used instead). |
| 293 | * The ``mimetype`` argument to the ``__init__`` methods of |
| 294 | :class:`~django.http.HttpResponse`, |
| 295 | :class:`~django.template.response.SimpleTemplateResponse`, and |
| 296 | :class:`~django.template.response.TemplateResponse`, will be removed. |
| 297 | ``content_type`` should be used instead. This also applies to the |
| 298 | :func:`~django.shortcuts.render_to_response` shortcut and |
| 299 | the sitemamp views, :func:`~django.contrib.sitemaps.views.index` and |
| 300 | :func:`~django.contrib.sitemaps.views.sitemap`. |
295 | 301 | |
296 | 302 | * When :class:`~django.http.HttpResponse` is instantiated with an iterator, |
297 | 303 | or when :attr:`~django.http.HttpResponse.content` is set to an iterator, |
diff --git a/docs/ref/contrib/admin/actions.txt b/docs/ref/contrib/admin/actions.txt
index d7eef62..0a302ec 100644
a
|
b
|
objects as JSON::
|
223 | 223 | from django.core import serializers |
224 | 224 | |
225 | 225 | def export_as_json(modeladmin, request, queryset): |
226 | | response = HttpResponse(mimetype="text/javascript") |
| 226 | response = HttpResponse(content_type="application/json") |
227 | 227 | serializers.serialize("json", queryset, stream=response) |
228 | 228 | return response |
229 | 229 | |
… |
… |
Conditionally enabling or disabling actions
|
356 | 356 | if 'delete_selected' in actions: |
357 | 357 | del actions['delete_selected'] |
358 | 358 | return actions |
359 | | |
360 | | |
diff --git a/docs/ref/template-response.txt b/docs/ref/template-response.txt
index 3f5e772..844b5fa 100644
a
|
b
|
Attributes
|
56 | 56 | Methods |
57 | 57 | ------- |
58 | 58 | |
59 | | .. method:: SimpleTemplateResponse.__init__(template, context=None, mimetype=None, status=None, content_type=None) |
| 59 | .. method:: SimpleTemplateResponse.__init__(template, context=None, content_type=None, status=None) |
60 | 60 | |
61 | 61 | Instantiates a |
62 | 62 | :class:`~django.template.response.SimpleTemplateResponse` object |
63 | | with the given template, context, MIME type and HTTP status. |
| 63 | with the given template, context, content type, and HTTP status. |
64 | 64 | |
65 | 65 | ``template`` |
66 | 66 | The full name of a template, or a sequence of template names. |
… |
… |
Methods
|
75 | 75 | The HTTP Status code for the response. |
76 | 76 | |
77 | 77 | ``content_type`` |
78 | | An alias for ``mimetype``. Historically, this parameter was only called |
79 | | ``mimetype``, but since this is actually the value included in the HTTP |
80 | | ``Content-Type`` header, it can also include the character set encoding, |
81 | | which makes it more than just a MIME type specification. If ``mimetype`` |
82 | | is specified (not ``None``), that value is used. Otherwise, |
83 | | ``content_type`` is used. If neither is given, |
| 78 | |
| 79 | .. versionchanged:: 1.5 |
| 80 | |
| 81 | Historically, this parameter was only called ``mimetype`` (now |
| 82 | deprecated), but since this is actually the value included in the HTTP |
| 83 | ``Content-Type`` header, it can also include the character set |
| 84 | encoding, which makes it more than just a MIME type specification. If |
| 85 | ``mimetype`` is specified (not ``None``), that value is used. |
| 86 | Otherwise, ``content_type`` is used. If neither is given, |
84 | 87 | :setting:`DEFAULT_CONTENT_TYPE` is used. |
85 | 88 | |
86 | 89 | |
… |
… |
TemplateResponse objects
|
144 | 147 | Methods |
145 | 148 | ------- |
146 | 149 | |
147 | | .. method:: TemplateResponse.__init__(request, template, context=None, mimetype=None, status=None, content_type=None, current_app=None) |
| 150 | .. method:: TemplateResponse.__init__(request, template, context=None, content_type=None, status=None, current_app=None) |
148 | 151 | |
149 | 152 | Instantiates an ``TemplateResponse`` object with the given |
150 | 153 | template, context, MIME type and HTTP status. |
… |
… |
Methods
|
165 | 168 | The HTTP Status code for the response. |
166 | 169 | |
167 | 170 | ``content_type`` |
168 | | An alias for ``mimetype``. Historically, this parameter was only called |
169 | | ``mimetype``, but since this is actually the value included in the HTTP |
170 | | ``Content-Type`` header, it can also include the character set encoding, |
171 | | which makes it more than just a MIME type specification. If ``mimetype`` |
172 | | is specified (not ``None``), that value is used. Otherwise, |
173 | | ``content_type`` is used. If neither is given, |
| 171 | |
| 172 | .. versionchanged:: 1.5 |
| 173 | |
| 174 | Historically, this parameter was only called ``mimetype`` (now |
| 175 | deprecated), but since this is actually the value included in the HTTP |
| 176 | ``Content-Type`` header, it can also include the character set |
| 177 | encoding, which makes it more than just a MIME type specification. If |
| 178 | ``mimetype`` is specified (not ``None``), that value is used. |
| 179 | Otherwise, ``content_type`` is used. If neither is given, |
174 | 180 | :setting:`DEFAULT_CONTENT_TYPE` is used. |
175 | 181 | |
176 | 182 | ``current_app`` |
diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt
index b1b4700..68860f1 100644
a
|
b
|
Optional arguments
|
50 | 50 | The MIME type to use for the resulting document. Defaults to the value of |
51 | 51 | the :setting:`DEFAULT_CONTENT_TYPE` setting. |
52 | 52 | |
| 53 | .. versionchanged:: 1.5 |
| 54 | This parameter used to be called ``mimetype``. |
| 55 | |
53 | 56 | ``status`` |
54 | 57 | The status code for the response. Defaults to ``200``. |
55 | 58 | |
… |
… |
This example is equivalent to::
|
87 | 90 | ``render_to_response`` |
88 | 91 | ====================== |
89 | 92 | |
90 | | .. function:: render_to_response(template_name[, dictionary][, context_instance][, mimetype]) |
| 93 | .. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type]) |
91 | 94 | |
92 | 95 | Renders a given template with a given context dictionary and returns an |
93 | 96 | :class:`~django.http.HttpResponse` object with that rendered text. |
… |
… |
Optional arguments
|
121 | 124 | my_data_dictionary, |
122 | 125 | context_instance=RequestContext(request)) |
123 | 126 | |
124 | | ``mimetype`` |
| 127 | ``content_type`` |
125 | 128 | The MIME type to use for the resulting document. Defaults to the value of |
126 | 129 | the :setting:`DEFAULT_CONTENT_TYPE` setting. |
127 | 130 | |
| 131 | .. versionchanged:: 1.5 |
| 132 | This parameter used to be called ``mimetype``. |
| 133 | |
| 134 | |
128 | 135 | Example |
129 | 136 | ------- |
130 | 137 | |
… |
… |
This example is equivalent to::
|
148 | 155 | t = loader.get_template('myapp/template.html') |
149 | 156 | c = Context({'foo': 'bar'}) |
150 | 157 | return HttpResponse(t.render(c), |
151 | | mimetype="application/xhtml+xml") |
| 158 | content_type="application/xhtml+xml") |
152 | 159 | |
153 | 160 | ``redirect`` |
154 | 161 | ============ |
diff --git a/tests/regressiontests/views/generic_urls.py b/tests/regressiontests/views/generic_urls.py
index 0f214d1..d504362 100644
a
|
b
|
urlpatterns += patterns('',
|
47 | 47 | urlpatterns += patterns('regressiontests.views.views', |
48 | 48 | (r'^shortcuts/render_to_response/$', 'render_to_response_view'), |
49 | 49 | (r'^shortcuts/render_to_response/request_context/$', 'render_to_response_view_with_request_context'), |
50 | | (r'^shortcuts/render_to_response/mimetype/$', 'render_to_response_view_with_mimetype'), |
| 50 | (r'^shortcuts/render_to_response/content_type/$', 'render_to_response_view_with_content_type'), |
51 | 51 | (r'^shortcuts/render/$', 'render_view'), |
52 | 52 | (r'^shortcuts/render/base_context/$', 'render_view_with_base_context'), |
53 | 53 | (r'^shortcuts/render/content_type/$', 'render_view_with_content_type'), |
diff --git a/tests/regressiontests/views/tests/shortcuts.py b/tests/regressiontests/views/tests/shortcuts.py
index 62bd82f..3a5df6a 100644
a
|
b
|
class ShortcutTests(TestCase):
|
21 | 21 | self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n') |
22 | 22 | self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') |
23 | 23 | |
24 | | def test_render_to_response_with_mimetype(self): |
25 | | response = self.client.get('/shortcuts/render_to_response/mimetype/') |
| 24 | def test_render_to_response_with_content_type(self): |
| 25 | response = self.client.get('/shortcuts/render_to_response/content_type/') |
26 | 26 | self.assertEqual(response.status_code, 200) |
27 | 27 | self.assertEqual(response.content, b'FOO.BAR..\n') |
28 | 28 | self.assertEqual(response['Content-Type'], 'application/x-rendertest') |
diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py
index 748f076..50ad98a 100644
a
|
b
|
def render_to_response_view_with_request_context(request):
|
68 | 68 | 'bar': 'BAR', |
69 | 69 | }, context_instance=RequestContext(request)) |
70 | 70 | |
71 | | def render_to_response_view_with_mimetype(request): |
| 71 | def render_to_response_view_with_content_type(request): |
72 | 72 | return render_to_response('debug/render_test.html', { |
73 | 73 | 'foo': 'FOO', |
74 | 74 | 'bar': 'BAR', |
75 | | }, mimetype='application/x-rendertest') |
| 75 | }, content_type='application/x-rendertest') |
76 | 76 | |
77 | 77 | def render_view(request): |
78 | 78 | return render(request, 'debug/render_test.html', { |
… |
… |
class Klass(object):
|
263 | 263 | return technical_500_response(request, *exc_info) |
264 | 264 | |
265 | 265 | def sensitive_method_view(request): |
266 | | return Klass().method(request) |
267 | | No newline at end of file |
| 266 | return Klass().method(request) |