diff options
| author | Alasdair Nicol <alasdair@thenicols.net> | 2015-12-23 21:14:27 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-23 18:31:24 -0500 |
| commit | e95c9c35d3f5bf2b82fed1fd940ed6b1a5cb5427 (patch) | |
| tree | d1259a99d5303e6aef7a7ea74de5968efa2401cd | |
| parent | 3f8b9056c0da53858bd365e55f99ebc8af7c966e (diff) | |
[1.8.x] Fixed #25854 -- Removed deprecated usage of template.render() with RequestContext in docs.
Backport of 32c7d93e5f0638c5a1ec8e2525c967be444fcef1 from master
| -rw-r--r-- | docs/intro/tutorial03.txt | 14 | ||||
| -rw-r--r-- | docs/topics/http/shortcuts.txt | 6 |
2 files changed, 10 insertions, 10 deletions
diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index 3705c0e7fc..6275e3730a 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -372,7 +372,7 @@ Now let's update our ``index`` view in ``polls/views.py`` to use the template: :filename: polls/views.py from django.http import HttpResponse - from django.template import RequestContext, loader + from django.template import loader from .models import Question @@ -380,10 +380,10 @@ Now let's update our ``index`` view in ``polls/views.py`` to use the template: def index(request): latest_question_list = Question.objects.order_by('-pub_date')[:5] template = loader.get_template('polls/index.html') - context = RequestContext(request, { + context = { 'latest_question_list': latest_question_list, - }) - return HttpResponse(template.render(context)) + } + return HttpResponse(template.render(context, request)) That code loads the template called ``polls/index.html`` and passes it a context. The context is a dictionary mapping template variable names to Python @@ -415,9 +415,9 @@ rewritten: return render(request, 'polls/index.html', context) Note that once we've done this in all these views, we no longer need to import -:mod:`~django.template.loader`, :class:`~django.template.RequestContext` and -:class:`~django.http.HttpResponse` (you'll want to keep ``HttpResponse`` if you -still have the stub methods for ``detail``, ``results``, and ``vote``). +:mod:`~django.template.loader` and :class:`~django.http.HttpResponse` (you'll +want to keep ``HttpResponse`` if you still have the stub methods for ``detail``, +``results``, and ``vote``). The :func:`~django.shortcuts.render` function takes the request object as its first argument, a template name as its second argument and a dictionary as its diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt index 4f418d7f69..c634a11f2f 100644 --- a/docs/topics/http/shortcuts.txt +++ b/docs/topics/http/shortcuts.txt @@ -109,13 +109,13 @@ MIME type :mimetype:`application/xhtml+xml`:: This example is equivalent to:: from django.http import HttpResponse - from django.template import RequestContext, loader + from django.template import loader def my_view(request): # View code here... t = loader.get_template('myapp/index.html') - c = RequestContext(request, {'foo': 'bar'}) - return HttpResponse(t.render(c), + c = {'foo': 'bar'} + return HttpResponse(t.render(c, request), content_type="application/xhtml+xml") ``render_to_response`` |
