diff options
Diffstat (limited to 'docs/intro/tutorial04.txt')
| -rw-r--r-- | docs/intro/tutorial04.txt | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/docs/intro/tutorial04.txt b/docs/intro/tutorial04.txt index 8abf2d395a..f7aa79e6f7 100644 --- a/docs/intro/tutorial04.txt +++ b/docs/intro/tutorial04.txt @@ -12,7 +12,8 @@ Write a simple form Let's update our poll detail template ("polls/detail.html") from the last tutorial, so that the template contains an HTML ``<form>`` element: -.. code-block:: html+django +.. snippet:: html+django + :filename: polls/templates/polls/detail.html <h1>{{ question.question_text }}</h1> @@ -54,12 +55,18 @@ A quick rundown: Now, let's create a Django view that handles the submitted data and does something with it. Remember, in :doc:`Tutorial 3 </intro/tutorial03>`, we -created a URLconf for the polls application that includes this line:: +created a URLconf for the polls application that includes this line: + +.. snippet:: + :filename: polls/urls.py url(r'^(?P<question_id>\d+)/vote/$', views.vote, name='vote'), We also created a dummy implementation of the ``vote()`` function. Let's -create a real version. Add the following to ``polls/views.py``:: +create a real version. Add the following to ``polls/views.py``: + +.. snippet:: + :filename: polls/views.py from django.shortcuts import get_object_or_404, render from django.http import HttpResponseRedirect, HttpResponse @@ -134,7 +141,10 @@ object. For more on :class:`~django.http.HttpRequest` objects, see the :doc:`request and response documentation </ref/request-response>`. After somebody votes in a question, the ``vote()`` view redirects to the results -page for the question. Let's write that view:: +page for the question. Let's write that view: + +.. snippet:: + :filename: polls/views.py from django.shortcuts import get_object_or_404, render @@ -149,7 +159,8 @@ redundancy later. Now, create a ``polls/results.html`` template: -.. code-block:: html+django +.. snippet:: html+django + :filename: polls/templates/polls/results.html <h1>{{ question.question_text }}</h1> @@ -205,7 +216,10 @@ Read on for details. Amend URLconf ------------- -First, open the ``polls/urls.py`` URLconf and change it like so:: +First, open the ``polls/urls.py`` URLconf and change it like so: + +.. snippet:: + :filename: polls/urls.py from django.conf.urls import patterns, url @@ -223,7 +237,10 @@ Amend views Next, we're going to remove our old ``index``, ``detail``, and ``results`` views and use Django's generic views instead. To do so, open the -``polls/views.py`` file and change it like so:: +``polls/views.py`` file and change it like so: + +.. snippet:: + :filename: polls/views.py from django.shortcuts import get_object_or_404, render from django.http import HttpResponseRedirect |
