summaryrefslogtreecommitdiff
path: root/docs/topics/forms
diff options
context:
space:
mode:
Diffstat (limited to 'docs/topics/forms')
-rw-r--r--docs/topics/forms/formsets.txt8
-rw-r--r--docs/topics/forms/modelforms.txt16
2 files changed, 9 insertions, 15 deletions
diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt
index 3e28e3fec7..5620693582 100644
--- a/docs/topics/forms/formsets.txt
+++ b/docs/topics/forms/formsets.txt
@@ -582,7 +582,7 @@ The only thing you will want to be aware of is making sure to use the
management form inside the template. Let's look at a sample view::
from django.forms import formset_factory
- from django.shortcuts import render_to_response
+ from django.shortcuts import render
from myapp.forms import ArticleForm
def manage_articles(request):
@@ -594,7 +594,7 @@ management form inside the template. Let's look at a sample view::
pass
else:
formset = ArticleFormSet()
- return render_to_response('manage_articles.html', {'formset': formset})
+ return render(request, 'manage_articles.html', {'formset': formset})
The ``manage_articles.html`` template might look like this:
@@ -659,7 +659,7 @@ more than one formset to be sent to a view without name clashing. Lets take
a look at how this might be accomplished::
from django.forms import formset_factory
- from django.shortcuts import render_to_response
+ from django.shortcuts import render
from myapp.forms import ArticleForm, BookForm
def manage_articles(request):
@@ -674,7 +674,7 @@ a look at how this might be accomplished::
else:
article_formset = ArticleFormSet(prefix='articles')
book_formset = BookFormSet(prefix='books')
- return render_to_response('manage_articles.html', {
+ return render(request, 'manage_articles.html', {
'article_formset': article_formset,
'book_formset': book_formset,
})
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 882478fc2a..67b8ba510d 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -954,7 +954,7 @@ Model formsets are very similar to formsets. Let's say we want to present a
formset to edit ``Author`` model instances::
from django.forms import modelformset_factory
- from django.shortcuts import render_to_response
+ from django.shortcuts import render
from myapp.models import Author
def manage_authors(request):
@@ -966,9 +966,7 @@ formset to edit ``Author`` model instances::
# do something.
else:
formset = AuthorFormSet()
- return render_to_response("manage_authors.html", {
- "formset": formset,
- })
+ return render(request, 'manage_authors.html', {'formset': formset})
As you can see, the view logic of a model formset isn't drastically different
than that of a "normal" formset. The only difference is that we call
@@ -1022,7 +1020,7 @@ As stated earlier, you can override the default queryset used by the model
formset::
from django.forms import modelformset_factory
- from django.shortcuts import render_to_response
+ from django.shortcuts import render
from myapp.models import Author
def manage_authors(request):
@@ -1035,9 +1033,7 @@ formset::
# Do something.
else:
formset = AuthorFormSet(queryset=Author.objects.filter(name__startswith='O'))
- return render_to_response("manage_authors.html", {
- "formset": formset,
- })
+ return render(request, 'manage_authors.html", {'formset': formset})
Note that we pass the ``queryset`` argument in both the ``POST`` and ``GET``
cases in this example.
@@ -1213,9 +1209,7 @@ of a model. Here's how you can do that::
return HttpResponseRedirect(author.get_absolute_url())
else:
formset = BookInlineFormSet(instance=author)
- return render_to_response("manage_books.html", {
- "formset": formset,
- })
+ return render(request, 'manage_books.html', {'formset': formset})
Notice how we pass ``instance`` in both the ``POST`` and ``GET`` cases.