Ticket #10504: tkt-10504.diff

File tkt-10504.diff, 3.6 KB (added by kenth, 13 years ago)
  • django/shortcuts/__init__.py

    diff --git a/django/shortcuts/__init__.py b/django/shortcuts/__init__.py
    index 9f97cae..5f527aa 100644
    a b def render_to_response(*args, **kwargs):  
    1616    Returns a HttpResponse whose content is filled with the result of calling
    1717    django.template.loader.render_to_string() with the passed arguments.
    1818    """
    19     httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
     19    httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None),
     20                           'content_type': kwargs.pop('content_type', None)}
    2021    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    2122
    2223def render(request, *args, **kwargs):
  • docs/topics/http/shortcuts.txt

    diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt
    index 9c05c6e..903c995 100644
    a b Optional arguments  
    127127    The MIME type to use for the resulting document. Defaults to the value of
    128128    the :setting:`DEFAULT_CONTENT_TYPE` setting.
    129129
     130``content_type``
     131
     132    .. versionadded:: 1.4
     133
     134    An alias for ``mimetype`` that corresponds more closely to the HTTP header
     135    Content-Type.
     136
    130137Example
    131138-------
    132139
  • tests/regressiontests/views/generic_urls.py

    diff --git a/tests/regressiontests/views/generic_urls.py b/tests/regressiontests/views/generic_urls.py
    index 40a6c01..2847a7b 100644
    a b urlpatterns += patterns('regressiontests.views.views',  
    100100    (r'^shortcuts/render_to_response/$', 'render_to_response_view'),
    101101    (r'^shortcuts/render_to_response/request_context/$', 'render_to_response_view_with_request_context'),
    102102    (r'^shortcuts/render_to_response/mimetype/$', 'render_to_response_view_with_mimetype'),
     103        (r'^shortcuts/render_to_response/content_type/$', 'render_to_response_view_with_content_type'),
    103104    (r'^shortcuts/render/$', 'render_view'),
    104105    (r'^shortcuts/render/base_context/$', 'render_view_with_base_context'),
    105106    (r'^shortcuts/render/content_type/$', 'render_view_with_content_type'),
  • tests/regressiontests/views/tests/shortcuts.py

    diff --git a/tests/regressiontests/views/tests/shortcuts.py b/tests/regressiontests/views/tests/shortcuts.py
    index 24bf6bb..1ad6cd5 100644
    a b class ShortcutTests(TestCase):  
    4444        self.assertEqual(response.content, 'FOO.BAR..\n')
    4545        self.assertEqual(response['Content-Type'], 'application/x-rendertest')
    4646
     47    def test_render_to_response_with_contenttype(self):
     48        response = self.client.get('/shortcuts/render_to_response/content_type/')
     49        self.assertEqual(response.status_code, 200)
     50        self.assertEqual(response.content, 'FOO.BAR..\n')
     51        self.assertEqual(response['Content-Type'], 'application/x-rendertest')
     52
    4753    def test_render(self):
    4854        response = self.client.get('/shortcuts/render/')
    4955        self.assertEqual(response.status_code, 200)
  • tests/regressiontests/views/views.py

    diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py
    index f2b4e79..468bd96 100644
    a b def render_to_response_view_with_mimetype(request):  
    9191        'bar': 'BAR',
    9292    }, mimetype='application/x-rendertest')
    9393
     94def render_to_response_view_with_content_type(request):
     95    return render_to_response('debug/render_test.html', {
     96        'foo': 'FOO',
     97        'bar': 'BAR',
     98    }, content_type='application/x-rendertest')
     99
    94100def render_view(request):
    95101    return render(request, 'debug/render_test.html', {
    96102        'foo': 'FOO',
Back to Top