summaryrefslogtreecommitdiff
path: root/docs/topics/http
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-12-22 10:21:24 -0500
committerTim Graham <timograham@gmail.com>2015-12-23 09:14:32 -0500
commit4d83b0163e15f8352fd17fa121e929842ff2b686 (patch)
treeb72a5b5bc18dc0eb64c7f49fcb85bbef9401aca4 /docs/topics/http
parentedf3b88f1ad8f6e900fb3273cc8a573d3d77ce16 (diff)
Fixed #25969 -- Replaced render_to_response() with render() in docs examples.
Diffstat (limited to 'docs/topics/http')
-rw-r--r--docs/topics/http/file-uploads.txt4
-rw-r--r--docs/topics/http/sessions.txt5
-rw-r--r--docs/topics/http/shortcuts.txt66
-rw-r--r--docs/topics/http/views.txt4
4 files changed, 15 insertions, 64 deletions
diff --git a/docs/topics/http/file-uploads.txt b/docs/topics/http/file-uploads.txt
index ea01dfc88e..06ec03ee61 100644
--- a/docs/topics/http/file-uploads.txt
+++ b/docs/topics/http/file-uploads.txt
@@ -45,7 +45,7 @@ form as described in :ref:`binding-uploaded-files`. This would look
something like::
from django.http import HttpResponseRedirect
- from django.shortcuts import render_to_response
+ from django.shortcuts import render
from .forms import UploadFileForm
# Imaginary function to handle an uploaded file.
@@ -59,7 +59,7 @@ something like::
return HttpResponseRedirect('/success/url/')
else:
form = UploadFileForm()
- return render_to_response('upload.html', {'form': form})
+ return render(request, 'upload.html', {'form': form})
Notice that we have to pass :attr:`request.FILES <django.http.HttpRequest.FILES>`
into the form's constructor; this is how file data gets bound into a form.
diff --git a/docs/topics/http/sessions.txt b/docs/topics/http/sessions.txt
index f96ab66039..9d58d1829a 100644
--- a/docs/topics/http/sessions.txt
+++ b/docs/topics/http/sessions.txt
@@ -451,6 +451,9 @@ yourself. Do this after you've verified that the test cookie worked.
Here's a typical usage example::
+ from django.http import HttpResponse
+ from django.shortcuts import render
+
def login(request):
if request.method == 'POST':
if request.session.test_cookie_worked():
@@ -459,7 +462,7 @@ Here's a typical usage example::
else:
return HttpResponse("Please enable cookies and try again.")
request.session.set_test_cookie()
- return render_to_response('foo/login_form.html')
+ return render(request, 'foo/login_form.html')
Using sessions out of views
===========================
diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt
index 5cb0b0b465..7828410f14 100644
--- a/docs/topics/http/shortcuts.txt
+++ b/docs/topics/http/shortcuts.txt
@@ -20,9 +20,6 @@ introduce controlled coupling for convenience's sake.
Combines a given template with a given context dictionary and returns an
:class:`~django.http.HttpResponse` object with that rendered text.
- :func:`render()` is the same as a call to :func:`render_to_response()` but
- it also makes the current request available in the template.
-
Django does not provide a shortcut function which returns a
:class:`~django.template.response.TemplateResponse` because the constructor
of :class:`~django.template.response.TemplateResponse` offers the same level
@@ -35,7 +32,10 @@ Required arguments
The request object used to generate this response.
``template_name``
- The full name of a template to use or sequence of template names.
+ The full name of a template to use or sequence of template names. If a
+ sequence is given, the first template that exists will be used. See the
+ :ref:`template loading documentation <template-loading>` for more
+ information on how templates are found.
Optional arguments
------------------
@@ -86,61 +86,9 @@ This example is equivalent to::
.. function:: render_to_response(template_name, context=None, content_type=None, status=None, using=None)
- Renders a given template with a given context dictionary and returns an
- :class:`~django.http.HttpResponse` object with that rendered text.
-
-Required arguments
-------------------
-
-``template_name``
- The full name of a template to use or sequence of template names. If a
- sequence is given, the first template that exists will be used. See the
- :ref:`template loading documentation <template-loading>` for more
- information on how templates are found.
-
-Optional arguments
-------------------
-
-``context``
- A dictionary of values to add to the template context. By default, this
- is an empty dictionary. If a value in the dictionary is callable, the
- view will call it just before rendering the template.
-
-``content_type``
- The MIME type to use for the resulting document. Defaults to the value of
- the :setting:`DEFAULT_CONTENT_TYPE` setting.
-
-``status``
- The status code for the response. Defaults to ``200``.
-
-``using``
- The :setting:`NAME <TEMPLATES-NAME>` of a template engine to use for
- loading the template.
-
-Example
--------
-
-The following example renders the template ``myapp/index.html`` with the
-MIME type :mimetype:`application/xhtml+xml`::
-
- from django.shortcuts import render_to_response
-
- def my_view(request):
- # View code here...
- return render_to_response('myapp/index.html', {"foo": "bar"},
- content_type="application/xhtml+xml")
-
-This example is equivalent to::
-
- from django.http import HttpResponse
- from django.template import Context, loader
-
- def my_view(request):
- # View code here...
- t = loader.get_template('myapp/index.html')
- c = Context({'foo': 'bar'})
- return HttpResponse(t.render(c),
- content_type="application/xhtml+xml")
+ This function preceded the introduction of :func:`render` and works
+ similarly except that it doesn't making the ``request`` available in the
+ response. It's not recommended and is likely to be deprecated in the future.
``redirect``
============
diff --git a/docs/topics/http/views.txt b/docs/topics/http/views.txt
index 26b28da6a2..c21012fa64 100644
--- a/docs/topics/http/views.txt
+++ b/docs/topics/http/views.txt
@@ -112,7 +112,7 @@ standard error page for your application, along with an HTTP error code 404.
Example usage::
from django.http import Http404
- from django.shortcuts import render_to_response
+ from django.shortcuts import render
from polls.models import Poll
def detail(request, poll_id):
@@ -120,7 +120,7 @@ Example usage::
p = Poll.objects.get(pk=poll_id)
except Poll.DoesNotExist:
raise Http404("Poll does not exist")
- return render_to_response('polls/detail.html', {'poll': p})
+ return render(request, 'polls/detail.html', {'poll': p})
In order to show customized HTML when Django returns a 404, you can create an
HTML template named ``404.html`` and place it in the top level of your