From d07d6ae1167f93f2e88b3743c070003a66a31b35 Mon Sep 17 00:00:00 2001 From: M Nasimul Haque Date: Mon, 23 Sep 2013 23:23:47 +0100 Subject: Fixed #20910 -- Added a "snippet" sphinx directive to allow prefixing a filename. Thanks Marc Tamlyn for the suggestion. --- docs/intro/tutorial04.txt | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'docs/intro/tutorial04.txt') 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 ``
`` element: -.. code-block:: html+django +.. snippet:: html+django + :filename: polls/templates/polls/detail.html

{{ question.question_text }}

@@ -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 `, 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\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 `. 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

{{ question.question_text }}

@@ -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 -- cgit v1.3