diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt
index fd3a04b..ea36913 100644
a
|
b
|
under "/content/polls/", or any other path root, and the app will still work.
|
533 | 533 | |
534 | 534 | All the poll app cares about is its relative path, not its absolute path. |
535 | 535 | |
| 536 | Removing hardcoded URLs in templates |
| 537 | ------------------------------------- |
| 538 | |
| 539 | Remember, when we wrote the link to a poll in our template, the link was |
| 540 | partially hardcoded like this: |
| 541 | |
| 542 | .. code-block:: html+django |
| 543 | |
| 544 | <li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li> |
| 545 | |
| 546 | Now to keep the advantage of decoupled URLs we've just introduced, we can use |
| 547 | the :ttag:`url` template tag and replace the hardcoded link: |
| 548 | |
| 549 | .. code-block:: html+django |
| 550 | |
| 551 | <li><a href="{% url 'polls.views.detail' poll.id %}">{{ poll.question }}</a></li> |
| 552 | |
536 | 553 | When you're comfortable with writing views, read :doc:`part 4 of this tutorial |
537 | 554 | </intro/tutorial04>` to learn about simple form processing and generic views. |
diff --git a/docs/intro/tutorial04.txt b/docs/intro/tutorial04.txt
index 44b9c16..5081853 100644
a
|
b
|
tutorial, so that the template contains an HTML ``<form>`` element:
|
18 | 18 | |
19 | 19 | {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} |
20 | 20 | |
21 | | <form action="/polls/{{ poll.id }}/vote/" method="post"> |
| 21 | <form action="{% url 'polls.views.vote' poll.id %}" method="post"> |
22 | 22 | {% csrf_token %} |
23 | 23 | {% for choice in poll.choice_set.all %} |
24 | 24 | <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" /> |
… |
… |
A quick rundown:
|
35 | 35 | selects one of the radio buttons and submits the form, it'll send the |
36 | 36 | POST data ``choice=3``. This is HTML Forms 101. |
37 | 37 | |
38 | | * We set the form's ``action`` to ``/polls/{{ poll.id }}/vote/``, and we |
| 38 | * We set the form's ``action`` to ``'polls.views.vote' poll.id``, and we |
39 | 39 | set ``method="post"``. Using ``method="post"`` (as opposed to |
40 | 40 | ``method="get"``) is very important, because the act of submitting this |
41 | 41 | form will alter data server-side. Whenever you create a form that alters |
… |
… |
Now, create a ``results.html`` template:
|
172 | 172 | {% endfor %} |
173 | 173 | </ul> |
174 | 174 | |
175 | | <a href="/polls/{{ poll.id }}/">Vote again?</a> |
| 175 | <a href="{% url 'polls.views.detail' poll.id %}">Vote again?</a> |
176 | 176 | |
177 | 177 | Now, go to ``/polls/1/`` in your browser and vote in the poll. You should see a |
178 | 178 | results page that gets updated each time you vote. If you submit the form |
… |
… |
Change it like so::
|
238 | 238 | ListView.as_view( |
239 | 239 | queryset=Poll.objects.order_by('-pub_date')[:5], |
240 | 240 | context_object_name='latest_poll_list', |
241 | | template_name='polls/index.html')), |
| 241 | template_name='polls/index.html'), |
| 242 | name='poll_index'), |
242 | 243 | url(r'^(?P<pk>\d+)/$', |
243 | 244 | DetailView.as_view( |
244 | 245 | model=Poll, |
245 | | template_name='polls/detail.html')), |
| 246 | template_name='polls/detail.html'), |
| 247 | name='poll_detail'), |
246 | 248 | url(r'^(?P<pk>\d+)/results/$', |
247 | 249 | DetailView.as_view( |
248 | 250 | model=Poll, |
… |
… |
two views abstract the concepts of "display a list of objects" and
|
265 | 267 | ``"pk"``, so we've changed ``poll_id`` to ``pk`` for the generic |
266 | 268 | views. |
267 | 269 | |
268 | | * We've added a name, ``poll_results``, to the results view so |
269 | | that we have a way to refer to its URL later on (see the |
| 270 | * We've added the ``name`` argument to the views (e.g. ``name='poll_results'``) |
| 271 | so that we have a way to refer to their URL later on (see the |
270 | 272 | documentation about :ref:`naming URL patterns |
271 | 273 | <naming-url-patterns>` for information). We're also using the |
272 | 274 | :func:`~django.conf.urls.url` function from |
… |
… |
function anymore -- generic views can be (and are) used multiple times
|
317 | 319 | |
318 | 320 | return HttpResponseRedirect(reverse('poll_results', args=(p.id,))) |
319 | 321 | |
| 322 | The same rule apply for the :ttag:`url` template tag. For example in the |
| 323 | ``results.html`` template: |
| 324 | |
| 325 | .. code-block:: html+django |
| 326 | |
| 327 | <a href="{% url 'poll_detail' poll.id %}">Vote again?</a> |
| 328 | |
320 | 329 | Run the server, and use your new polling app based on generic views. |
321 | 330 | |
322 | 331 | For full details on generic views, see the :doc:`generic views documentation |