diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2012-08-10 12:40:37 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2012-08-10 12:40:37 +0100 |
| commit | 184cf9ab798d5b25d855649ddb2ca580949778df (patch) | |
| tree | 8512633ec04a6979b0953e32e73c9a43d09e5805 /docs/intro | |
| parent | c4b2a3262cc79383d6562cfc7e9af20135c8e0bf (diff) | |
| parent | 7275576235ae2e87f3de7b0facb3f9b0a2368f28 (diff) | |
Merge branch 'master' into schema-alteration
Diffstat (limited to 'docs/intro')
| -rw-r--r-- | docs/intro/_images/admin15t.png | bin | 0 -> 22805 bytes | |||
| -rw-r--r-- | docs/intro/install.txt | 3 | ||||
| -rw-r--r-- | docs/intro/tutorial01.txt | 10 | ||||
| -rw-r--r-- | docs/intro/tutorial02.txt | 8 | ||||
| -rw-r--r-- | docs/intro/tutorial03.txt | 17 | ||||
| -rw-r--r-- | docs/intro/tutorial04.txt | 23 |
6 files changed, 45 insertions, 16 deletions
diff --git a/docs/intro/_images/admin15t.png b/docs/intro/_images/admin15t.png Binary files differnew file mode 100644 index 0000000000..999d0519fb --- /dev/null +++ b/docs/intro/_images/admin15t.png diff --git a/docs/intro/install.txt b/docs/intro/install.txt index 7e8c7db7b3..70c8034c5d 100644 --- a/docs/intro/install.txt +++ b/docs/intro/install.txt @@ -84,8 +84,9 @@ Then at the Python prompt, try to import Django:: >>> import django >>> print(django.get_version()) - 1.4 + 1.5 +You may have another version of Django installed. That's it! ---------- diff --git a/docs/intro/tutorial01.txt b/docs/intro/tutorial01.txt index 250c0f1f41..1e2231d1e0 100644 --- a/docs/intro/tutorial01.txt +++ b/docs/intro/tutorial01.txt @@ -52,7 +52,8 @@ code, then run the following command: django-admin.py startproject mysite -This will create a ``mysite`` directory in your current directory. +This will create a ``mysite`` directory in your current directory. If it didn't +work, see :doc:`Troubleshooting </faq/troubleshooting>`. .. admonition:: Script name may differ in distribution packages @@ -78,13 +79,6 @@ This will create a ``mysite`` directory in your current directory. ``django`` (which will conflict with Django itself) or ``test`` (which conflicts with a built-in Python package). -:doc:`django-admin.py </ref/django-admin>` should be on your system path if you -installed Django via ``python setup.py``. If it's not on your path, you can find -it in ``site-packages/django/bin``, where ``site-packages`` is a directory -within your Python installation. Consider symlinking to :doc:`django-admin.py -</ref/django-admin>` from some place on your path, such as -:file:`/usr/local/bin`. - .. admonition:: Where should this code live? If your background is in PHP, you're probably used to putting code under the diff --git a/docs/intro/tutorial02.txt b/docs/intro/tutorial02.txt index 84da36be86..fd13230c8b 100644 --- a/docs/intro/tutorial02.txt +++ b/docs/intro/tutorial02.txt @@ -311,6 +311,14 @@ It works like this: There are three slots for related Choices -- as specified by ``extra`` -- and each time you come back to the "Change" page for an already-created object, you get another three extra slots. +At the end of the three current slots you will find an "Add another Choice" +link. If you click on it, a new slot will be added. If you want to remove the +added slot, you can click on the X to the top right of the added slot. Note +that you can't remove the original three slots. This image shows an added slot: + +.. image:: _images/admin15t.png + :alt: Additional slot added dynamically + One small problem, though. It takes a lot of screen space to display all the fields for entering related ``Choice`` objects. For that reason, Django offers a tabular way of displaying inline related objects; you just need to change diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt index fd3a04ba93..d15b2f43ae 100644 --- a/docs/intro/tutorial03.txt +++ b/docs/intro/tutorial03.txt @@ -533,5 +533,22 @@ under "/content/polls/", or any other path root, and the app will still work. All the poll app cares about is its relative path, not its absolute path. +Removing hardcoded URLs in templates +------------------------------------ + +Remember, when we wrote the link to a poll in our template, the link was +partially hardcoded like this: + +.. code-block:: html+django + + <li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li> + +To use the decoupled URLs we've just introduced, replace the hardcoded link +with the :ttag:`url` template tag: + +.. code-block:: html+django + + <li><a href="{% url 'polls.views.detail' poll.id %}">{{ poll.question }}</a></li> + When you're comfortable with writing views, read :doc:`part 4 of this tutorial </intro/tutorial04>` to learn about simple form processing and generic views. diff --git a/docs/intro/tutorial04.txt b/docs/intro/tutorial04.txt index 44b9c16c2a..31680ea5e5 100644 --- a/docs/intro/tutorial04.txt +++ b/docs/intro/tutorial04.txt @@ -18,7 +18,7 @@ tutorial, so that the template contains an HTML ``<form>`` element: {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} - <form action="/polls/{{ poll.id }}/vote/" method="post"> + <form action="{% url 'polls.views.vote' poll.id %}" method="post"> {% csrf_token %} {% for choice in poll.choice_set.all %} <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" /> @@ -35,7 +35,7 @@ A quick rundown: selects one of the radio buttons and submits the form, it'll send the POST data ``choice=3``. This is HTML Forms 101. -* We set the form's ``action`` to ``/polls/{{ poll.id }}/vote/``, and we +* We set the form's ``action`` to ``{% url 'polls.views.vote' poll.id %}``, and we set ``method="post"``. Using ``method="post"`` (as opposed to ``method="get"``) is very important, because the act of submitting this form will alter data server-side. Whenever you create a form that alters @@ -172,7 +172,7 @@ Now, create a ``results.html`` template: {% endfor %} </ul> - <a href="/polls/{{ poll.id }}/">Vote again?</a> + <a href="{% url 'polls.views.detail' poll.id %}">Vote again?</a> Now, go to ``/polls/1/`` in your browser and vote in the poll. You should see a results page that gets updated each time you vote. If you submit the form @@ -238,11 +238,13 @@ Change it like so:: ListView.as_view( queryset=Poll.objects.order_by('-pub_date')[:5], context_object_name='latest_poll_list', - template_name='polls/index.html')), + template_name='polls/index.html'), + name='poll_index'), url(r'^(?P<pk>\d+)/$', DetailView.as_view( model=Poll, - template_name='polls/detail.html')), + template_name='polls/detail.html'), + name='poll_detail'), url(r'^(?P<pk>\d+)/results/$', DetailView.as_view( model=Poll, @@ -265,8 +267,8 @@ two views abstract the concepts of "display a list of objects" and ``"pk"``, so we've changed ``poll_id`` to ``pk`` for the generic views. -* We've added a name, ``poll_results``, to the results view so - that we have a way to refer to its URL later on (see the +* We've added the ``name`` argument to the views (e.g. ``name='poll_results'``) + so that we have a way to refer to their URL later on (see the documentation about :ref:`naming URL patterns <naming-url-patterns>` for information). We're also using the :func:`~django.conf.urls.url` function from @@ -317,6 +319,13 @@ function anymore -- generic views can be (and are) used multiple times return HttpResponseRedirect(reverse('poll_results', args=(p.id,))) +The same rule apply for the :ttag:`url` template tag. For example in the +``results.html`` template: + +.. code-block:: html+django + + <a href="{% url 'poll_detail' poll.id %}">Vote again?</a> + Run the server, and use your new polling app based on generic views. For full details on generic views, see the :doc:`generic views documentation |
