diff --git a/django/shortcuts.py b/django/shortcuts.py index 7ab1df0e9d2..eda6f8813cd 100644 --- a/django/shortcuts.py +++ b/django/shortcuts.py @@ -3,31 +3,14 @@ This module collects helper functions and classes that "span" multiple levels of MVC. In other words, these functions/classes introduce controlled coupling for convenience's sake. """ -import warnings - from django.http import ( Http404, HttpResponse, HttpResponsePermanentRedirect, HttpResponseRedirect, ) from django.template import loader from django.urls import NoReverseMatch, reverse -from django.utils.deprecation import RemovedInDjango30Warning from django.utils.functional import Promise -def render_to_response(template_name, context=None, content_type=None, status=None, using=None): - """ - Return a HttpResponse whose content is filled with the result of calling - django.template.loader.render_to_string() with the passed arguments. - """ - warnings.warn( - 'render_to_response() is deprecated in favor of render(). It has the ' - 'same signature except that it also requires a request.', - RemovedInDjango30Warning, stacklevel=2, - ) - content = loader.render_to_string(template_name, context, using=using) - return HttpResponse(content, content_type, status) - - def render(request, template_name, context=None, content_type=None, status=None, using=None): """ Return a HttpResponse whose content is filled with the result of calling diff --git a/docs/releases/3.0.txt b/docs/releases/3.0.txt index 46397061465..c07a995bd6b 100644 --- a/docs/releases/3.0.txt +++ b/docs/releases/3.0.txt @@ -238,6 +238,8 @@ to remove usage of these features. * The ``django.db.backends.postgresql_psycopg2`` module is removed. +* ``django.shortcuts.render_to_response()`` is removed. + See :ref:`deprecated-features-2.1` for details on these changes, including how to remove usage of these features. diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt index 1aca4ce2870..a0eac390128 100644 --- a/docs/topics/http/shortcuts.txt +++ b/docs/topics/http/shortcuts.txt @@ -81,17 +81,6 @@ This example is equivalent to:: c = {'foo': 'bar'} return HttpResponse(t.render(c, request), content_type='application/xhtml+xml') -``render_to_response()`` -======================== - -.. function:: render_to_response(template_name, context=None, content_type=None, status=None, using=None) - - .. deprecated:: 2.0 - - This function preceded the introduction of :func:`render` and works - similarly except that it doesn't make the ``request`` available in the - response. - ``redirect()`` ============== diff --git a/tests/shortcuts/test_render_to_response.py b/tests/shortcuts/test_render_to_response.py deleted file mode 100644 index 7bf7ac9ad6b..00000000000 --- a/tests/shortcuts/test_render_to_response.py +++ /dev/null @@ -1,39 +0,0 @@ -from django.test import SimpleTestCase, ignore_warnings, override_settings -from django.test.utils import require_jinja2 -from django.utils.deprecation import RemovedInDjango30Warning - - -@ignore_warnings(category=RemovedInDjango30Warning) -@override_settings(ROOT_URLCONF='shortcuts.urls') -class RenderToResponseTests(SimpleTestCase): - - def test_render_to_response(self): - response = self.client.get('/render_to_response/') - self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, b'FOO.BAR..\n') - self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') - - def test_render_to_response_with_multiple_templates(self): - response = self.client.get('/render_to_response/multiple_templates/') - self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, b'FOO.BAR..\n') - - def test_render_to_response_with_content_type(self): - response = self.client.get('/render_to_response/content_type/') - self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, b'FOO.BAR..\n') - self.assertEqual(response['Content-Type'], 'application/x-rendertest') - - def test_render_to_response_with_status(self): - response = self.client.get('/render_to_response/status/') - self.assertEqual(response.status_code, 403) - self.assertEqual(response.content, b'FOO.BAR..\n') - - @require_jinja2 - def test_render_to_response_with_using(self): - response = self.client.get('/render_to_response/using/') - self.assertEqual(response.content, b'DTL\n') - response = self.client.get('/render_to_response/using/?using=django') - self.assertEqual(response.content, b'DTL\n') - response = self.client.get('/render_to_response/using/?using=jinja2') - self.assertEqual(response.content, b'Jinja2\n') diff --git a/tests/shortcuts/urls.py b/tests/shortcuts/urls.py index 0ac994b7d31..a506896bcfb 100644 --- a/tests/shortcuts/urls.py +++ b/tests/shortcuts/urls.py @@ -3,11 +3,6 @@ from django.urls import path from . import views urlpatterns = [ - path('render_to_response/', views.render_to_response_view), - path('render_to_response/multiple_templates/', views.render_to_response_view_with_multiple_templates), - path('render_to_response/content_type/', views.render_to_response_view_with_content_type), - path('render_to_response/status/', views.render_to_response_view_with_status), - path('render_to_response/using/', views.render_to_response_view_with_using), path('render/', views.render_view), path('render/multiple_templates/', views.render_view_with_multiple_templates), path('render/content_type/', views.render_view_with_content_type), diff --git a/tests/shortcuts/views.py b/tests/shortcuts/views.py index 6914a5e3953..bba17b3eeab 100644 --- a/tests/shortcuts/views.py +++ b/tests/shortcuts/views.py @@ -1,44 +1,4 @@ -from django.shortcuts import render, render_to_response - - -def render_to_response_view(request): - return render_to_response('shortcuts/render_test.html', { - 'foo': 'FOO', - 'bar': 'BAR', - }) - - -def render_to_response_view_with_multiple_templates(request): - return render_to_response([ - 'shortcuts/no_such_template.html', - 'shortcuts/render_test.html', - ], { - 'foo': 'FOO', - 'bar': 'BAR', - }) - - -def render_to_response_view_with_content_type(request): - return render_to_response('shortcuts/render_test.html', { - 'foo': 'FOO', - 'bar': 'BAR', - }, content_type='application/x-rendertest') - - -def render_to_response_view_with_status(request): - return render_to_response('shortcuts/render_test.html', { - 'foo': 'FOO', - 'bar': 'BAR', - }, status=403) - - -def render_to_response_view_with_using(request): - using = request.GET.get('using') - return render_to_response('shortcuts/using.html', using=using) - - -def context_processor(request): - return {'bar': 'context processor output'} +from django.shortcuts import render def render_view(request):