summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-10-14 20:10:13 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-10-14 20:10:13 +0000
commitf71f8546283dbdf698c7578f8f9154045c84f9e7 (patch)
tree1ae0aa237970d1b67ec8504d9f3f425305b3e155 /docs
parentb773bf45c3011dc95617dcbec9584c8d139c27cc (diff)
Fixed #626 -- Moved template modules to django.core.template package. django.core.template_loader is deprecated, in favor of django.core.template.loader.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@867 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/forms.txt36
-rw-r--r--docs/sessions.txt4
-rw-r--r--docs/templates_python.txt10
-rw-r--r--docs/tutorial03.txt9
-rw-r--r--docs/tutorial04.txt4
5 files changed, 18 insertions, 45 deletions
diff --git a/docs/forms.txt b/docs/forms.txt
index c93db95bcd..969ebd428d 100644
--- a/docs/forms.txt
+++ b/docs/forms.txt
@@ -65,9 +65,8 @@ Using the ``AddManipulator``
We'll start with the ``AddManipulator``. Here's a very simple view that takes
POSTed data from the browser and creates a new ``Place`` object::
- from django.core import template_loader
from django.core.exceptions import Http404
- from django.core.extensions import DjangoContext as Context
+ from django.core.extensions import render_to_response
from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
from django.models.places import places
from django.core import formfields
@@ -112,13 +111,7 @@ view with a form that submits to this flawed creation view::
# Create a FormWrapper object that the template can use. Ignore
# the last two arguments to FormWrapper for now.
form = formfields.FormWrapper(places.AddManipulator(), {}, {})
-
- # Create a template, context and response.
- t = template_loader.get_template('places/naive_create_form')
- c = Context(request, {
- 'form': form
- })
- return HttpResponse(t.render(c))
+ return render_to_response('places/naive_create_form', {'form': form})
(This view, as well as all the following ones, has the same imports as in the
first example above.)
@@ -169,11 +162,7 @@ creation view that takes validation into account::
# Check for validation errors
errors = manipulator.get_validation_errors(new_data)
if errors:
- t = template_loader.get_template('places/errors')
- c = Context(request, {
- 'errors': errors
- }
- return HttpResponse(t.render(c))
+ return render_to_response('places/errors', {'errors': errors})
else:
manipulator.do_html2python(request.POST)
new_place = manipulator.save(request.POST)
@@ -245,11 +234,7 @@ Below is the finished view::
# Create the FormWrapper, template, context, response.
form = formfields.FormWrapper(manipulator, new_data, errors)
- t = template_loader.get_template("places/create_form")
- c = Context(request, {
- 'form': form,
- })
- return HttpResponse(t.render(c))
+ return render_to_response('places/create_form', {'form': form})
and here's the ``create_form`` template::
@@ -338,12 +323,7 @@ about editing an existing one? It's shockingly similar to creating a new one::
new_data = place.__dict__
form = formfields.FormWrapper(manipulator, new_data, errors)
- t = template_loader.get_template("places/edit_form")
- c = Context(request, {
- 'form': form,
- 'place': place,
- })
- return HttpResponse(t.render(c))
+ return render_to_response('places/edit_form', {'form': form, 'place': place})
The only real differences are:
@@ -422,11 +402,7 @@ Here's a simple function that might drive the above form::
else:
errors = new_data = {}
form = formfields.FormWrapper(manipulator, new_data, errors)
- t = template_loader.get_template("contact_form")
- c = Context(request, {
- 'form': form,
- })
- return HttpResponse(t.render(c))
+ return render_to_response('contact_form', {'form': form})
Validators
==========
diff --git a/docs/sessions.txt b/docs/sessions.txt
index 22d06fdedd..b18ca25a2c 100644
--- a/docs/sessions.txt
+++ b/docs/sessions.txt
@@ -136,9 +136,7 @@ Here's a typical usage example::
else:
return HttpResponse("Please enable cookies and try again.")
request.session.set_test_cookie()
- t = template_loader.get_template("foo/login_form")
- c = Context(request)
- return HttpResponse(t.render(c))
+ return render_to_response('foo/login_form')
Using sessions out of views
===========================
diff --git a/docs/templates_python.txt b/docs/templates_python.txt
index 39b768429b..bd8aea62c7 100644
--- a/docs/templates_python.txt
+++ b/docs/templates_python.txt
@@ -307,12 +307,12 @@ The Python API
Django has two ways to load templates from files:
-``django.core.template_loader.get_template(template_name)``
+``django.core.template.loader.get_template(template_name)``
``get_template`` returns the compiled template (a ``Template`` object) for
the template with the given name. If the template doesn't exist, it raises
``django.core.template.TemplateDoesNotExist``.
-``django.core.template_loader.select_template(template_name_list)``
+``django.core.template.loader.select_template(template_name_list)``
``select_template`` is just like ``get_template``, except it takes a list
of template names. Of the list, it returns the first template that exists.
@@ -398,8 +398,8 @@ Python code, depending on whether you're writing filters or tags.
.. admonition:: Behind the scenes
For a ton of examples, read the source code for Django's default filters
- and tags. They're in ``django/core/defaultfilters.py`` and
- ``django/core/defaulttags.py``, respectively.
+ and tags. They're in ``django/core/template/defaultfilters.py`` and
+ ``django/core/template/defaulttags.py``, respectively.
Writing custom template filters
-------------------------------
@@ -710,4 +710,4 @@ The only new concept here is the ``self.nodelist.render(context)`` in
For more examples of complex rendering, see the source code for ``{% if %}``,
``{% for %}``, ``{% ifequal %}`` and ``{% ifchanged %}``. They live in
-``django/core/defaulttags.py``.
+``django/core/template/defaulttags.py``.
diff --git a/docs/tutorial03.txt b/docs/tutorial03.txt
index 84fb64abfe..f602bf2ebd 100644
--- a/docs/tutorial03.txt
+++ b/docs/tutorial03.txt
@@ -191,14 +191,13 @@ There's a problem here, though: The page's design is hard-coded in the view. If
you want to change the way the page looks, you'll have to edit this Python code.
So let's use Django's template system to separate the design from Python::
- from django.core import template_loader
- from django.core.template import Context
+ from django.core.template import Context, loader
from django.models.polls import polls
from django.utils.httpwrappers import HttpResponse
def index(request):
latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
- t = template_loader.get_template('polls/index')
+ t = loader.get_template('polls/index')
c = Context({
'latest_poll_list': latest_poll_list,
})
@@ -224,7 +223,7 @@ and feel" section of Tutorial 2.
When you've done that, create a directory ``polls`` in your template directory.
Within that, create a file called ``index.html``. Django requires that
templates have ".html" extension. Note that our
-``template_loader.get_template('polls/index')`` code from above maps to
+``loader.get_template('polls/index')`` code from above maps to
"[template_directory]/polls/index.html" on the filesystem.
Put the following code in that template::
@@ -256,7 +255,7 @@ provides a shortcut. Here's the full ``index()`` view, rewritten::
latest_poll_list = polls.get_list(order_by=['-pub_date'], limit=5)
return render_to_response('polls/index', {'latest_poll_list': latest_poll_list})
-Note that we no longer need to import ``template_loader``, ``Context`` or
+Note that we no longer need to import ``loader``, ``Context`` or
``HttpResponse``.
The ``render_to_response()`` function takes a template name as its first
diff --git a/docs/tutorial04.txt b/docs/tutorial04.txt
index 3e6d6205bb..737d8deb1f 100644
--- a/docs/tutorial04.txt
+++ b/docs/tutorial04.txt
@@ -197,8 +197,8 @@ objects" and "display a detail page for a particular type of object."
By default, the ``object_detail`` generic view uses a template called
``<app_label>/<module_name>_detail``. In our case, it'll use the template
``"polls/polls_detail"``. Thus, rename your ``polls/detail.html`` template to
-``polls/polls_detail.html``, and change the ``template_loader.get_template()``
-line in ``vote()``.
+``polls/polls_detail.html``, and change the ``render_to_response()`` line in
+``vote()``.
Similarly, the ``object_list`` generic view uses a template called
``<app_label>/<module_name>_list``. Thus, rename ``polls/index.html`` to