~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to docs/intro/tutorial04.txt

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-10-12 11:34:35 UTC
  • mfrom: (1.2.7 upstream)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: james.westby@ubuntu.com-20101012113435-9lnsrh0i3mxozbt0
Tags: upstream-1.2.3
ImportĀ upstreamĀ versionĀ 1.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
.. _intro-tutorial04:
2
 
 
3
1
=====================================
4
2
Writing your first Django app, part 4
5
3
=====================================
6
4
 
7
 
This tutorial begins where :ref:`Tutorial 3 <intro-tutorial03>` left off. We're
 
5
This tutorial begins where :doc:`Tutorial 3 </intro/tutorial03>` left off. We're
8
6
continuing the Web-poll application and will focus on simple form processing and
9
7
cutting down our code.
10
8
 
70
68
:ref:`RequestContext <subclassing-context-requestcontext>`.
71
69
 
72
70
Now, let's create a Django view that handles the submitted data and does
73
 
something with it. Remember, in :ref:`Tutorial 3 <intro-tutorial03>`, we
 
71
something with it. Remember, in :doc:`Tutorial 3 </intro/tutorial03>`, we
74
72
created a URLconf for the polls application that includes this line::
75
73
 
76
74
    (r'^(?P<poll_id>\d+)/vote/$', 'vote'),
149
147
 
150
148
As mentioned in Tutorial 3, ``request`` is a :class:`~django.http.HttpRequest`
151
149
object. For more on :class:`~django.http.HttpRequest` objects, see the
152
 
:ref:`request and response documentation <ref-request-response>`.
 
150
:doc:`request and response documentation </ref/request-response>`.
153
151
 
154
152
After somebody votes in a poll, the ``vote()`` view redirects to the results
155
153
page for the poll. Let's write that view::
158
156
        p = get_object_or_404(Poll, pk=poll_id)
159
157
        return render_to_response('polls/results.html', {'poll': p})
160
158
 
161
 
This is almost exactly the same as the ``detail()`` view from :ref:`Tutorial 3
162
 
<intro-tutorial03>`. The only difference is the template name. We'll fix this
 
159
This is almost exactly the same as the ``detail()`` view from :doc:`Tutorial 3
 
160
</intro/tutorial03>`. The only difference is the template name. We'll fix this
163
161
redundancy later.
164
162
 
165
163
Now, create a ``results.html`` template:
183
181
Use generic views: Less code is better
184
182
======================================
185
183
 
186
 
The ``detail()`` (from :ref:`Tutorial 3 <intro-tutorial03>`) and ``results()``
 
184
The ``detail()`` (from :doc:`Tutorial 3 </intro/tutorial03>`) and ``results()``
187
185
views are stupidly simple -- and, as mentioned above, redundant. The ``index()``
188
186
view (also from Tutorial 3), which displays a list of polls, is similar.
189
187
 
328
326
 
329
327
Run the server, and use your new polling app based on generic views.
330
328
 
331
 
For full details on generic views, see the :ref:`generic views documentation
332
 
<topics-http-generic-views>`.
 
329
For full details on generic views, see the :doc:`generic views documentation
 
330
</topics/http/generic-views>`.
333
331
 
334
332
Coming soon
335
333
===========
344
342
    * Advanced admin features: Permissions
345
343
    * Advanced admin features: Custom JavaScript
346
344
 
347
 
In the meantime, you might want to check out some pointers on :ref:`where to go
348
 
from here <intro-whatsnext>`
 
345
In the meantime, you might want to check out some pointers on :doc:`where to go
 
346
from here </intro/whatsnext>`