Refs #25978 -- Removed shortcuts.render_to_response() per deprecation timeline.
This commit is contained in:
parent
944469939b
commit
573ec714e5
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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()``
|
||||
==============
|
||||
|
||||
|
|
|
@ -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')
|
|
@ -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),
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue