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/tutorial03.txt | 67 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 15 deletions(-) (limited to 'docs/intro/tutorial03.txt') diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index 06707f2da8..2e0159f1db 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -84,7 +84,10 @@ Your app directory should now look like:: urls.py views.py -In the ``polls/urls.py`` file include the following code:: +In the ``polls/urls.py`` file include the following code: + +.. snippet:: + :filename: polls/urls.py from django.conf.urls import patterns, url @@ -96,7 +99,10 @@ In the ``polls/urls.py`` file include the following code:: The next step is to point the root URLconf at the ``polls.urls`` module. In ``mysite/urls.py`` insert an :func:`~django.conf.urls.include`, leaving you -with:: +with: + +.. snippet:: + :filename: mysite/urls.py from django.conf.urls import patterns, include, url @@ -172,7 +178,10 @@ Writing more views ================== Now let's add a few more views to ``polls/views.py``. These views are -slightly different, because they take an argument:: +slightly different, because they take an argument: + +.. snippet:: + :filename: polls/views.py def detail(request, question_id): return HttpResponse("You're looking at question %s." % question_id) @@ -185,7 +194,10 @@ slightly different, because they take an argument:: return HttpResponse("You're voting on question %s." % question_id) Wire these new views into the ``polls.urls`` module by adding the following -:func:`~django.conf.urls.url` calls:: +:func:`~django.conf.urls.url` calls: + +.. snippet:: + :filename: polls/urls.py from django.conf.urls import patterns, url @@ -269,7 +281,10 @@ All Django wants is that :class:`~django.http.HttpResponse`. Or an exception. Because it's convenient, let's use Django's own database API, which we covered in :doc:`Tutorial 1 `. Here's one stab at the ``index()`` view, which displays the latest 5 poll questions in the system, separated by -commas, according to publication date:: +commas, according to publication date: + +.. snippet:: + :filename: polls/views.py from django.http import HttpResponse @@ -327,7 +342,8 @@ Django simply as ``polls/index.html``. Put the following code in that template: -.. code-block:: html+django +.. snippet:: html+django + :filename: polls/templates/polls/index.html {% if latest_question_list %}