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

« back to all changes in this revision

Viewing changes to docs/topics/templates.txt

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
                <li>{{ athlete.name }}</li>
188
188
            {% endfor %}
189
189
            </ul>
190
 
        
191
 
    :ttag:`if` and :ttag:`else`
 
190
 
 
191
    :ttag:`if` and ``else``
192
192
        Evaluates a variable, and if that variable is "true" the contents of the
193
193
        block are displayed::
194
194
 
200
200
 
201
201
        In the above, if ``athlete_list`` is not empty, the number of athletes
202
202
        will be displayed by the ``{{ athlete_list|length }}`` variable.
203
 
        
204
 
    :ttag:`ifequal` and :ttag:`ifnotequal`
205
 
        Display some contents if two arguments are or are not equal. For example::
206
 
 
207
 
            {% ifequal athlete.name coach.name %}
208
 
                ...
209
 
            {% endifequal %}
210
 
 
211
 
        Or::
212
 
 
213
 
            {% ifnotequal athlete.name "Joe" %}
214
 
                ...
215
 
            {% endifnotequal %}
216
 
    
 
203
 
 
204
        You can also use filters and various operators in the ``if`` tag::
 
205
 
 
206
            {% if athlete_list|length > 1 %}
 
207
               Team: {% for athlete in athlete_list %} ... {% endfor %}
 
208
            {% else %}
 
209
               Athlete: {{ athlete_list.0.name }}
 
210
            {% endif %}
 
211
 
217
212
    :ttag:`block` and :ttag:`extends`
218
213
        Set up `template inheritance`_ (see below), a powerful way
219
214
        of cutting down on "boilerplate" in templates.
582
577
============================
583
578
 
584
579
Django's admin interface includes a complete reference of all template tags and
585
 
filters available for a given site. To see it, go to your admin interface and
586
 
click the "Documentation" link in the upper right of the page.
 
580
filters available for a given site. To activate it, follow these steps:
 
581
 
 
582
    * Add :mod:`django.contrib.admindocs` to your :setting:`INSTALLED_APPS`.
 
583
    * Add ``(r'^admin/doc/', include('django.contrib.admindocs.urls'))`` to your
 
584
      :data:`urlpatterns`. Make sure it's included *before* the ``r'^admin/'``
 
585
      entry, so that requests to ``/admin/doc/`` don't get handled by the
 
586
      latter entry.
 
587
    * Install the docutils module (http://docutils.sf.net/).
 
588
 
 
589
After you've followed those steps, you can start browsing the documentation by
 
590
going to your admin interface and clicking the "Documentation" link in the
 
591
upper right of the page.
587
592
 
588
593
The reference is divided into 4 sections: tags, filters, models, and views.
589
594