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

« back to all changes in this revision

Viewing changes to docs/ref/templates/builtins.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:
51
51
 
52
52
Ignore everything between ``{% comment %}`` and ``{% endcomment %}``
53
53
 
 
54
.. templatetag:: csrf_token
 
55
 
 
56
csrf_token
 
57
~~~~~~~~~~
 
58
 
 
59
.. versionadded:: 1.1.2
 
60
 
 
61
In the Django 1.1.X series, this is a no-op tag that returns an empty string for
 
62
future compatibility purposes.  In Django 1.2 and later, it is used for CSRF
 
63
protection, as described in the documentation for :ref:`Cross Site Request
 
64
Forgeries <ref-contrib-csrf>`.
 
65
 
54
66
.. templatetag:: cycle
55
67
 
56
68
cycle
101
113
Values enclosed in single (``'``) or double quotes (``"``) are treated as
102
114
string literals, while values without quotes are treated as template variables.
103
115
 
104
 
Note that the variables included in the cycle will not be escaped. This is
105
 
because template tags do not escape their content. If you want to escape the
106
 
variables in the cycle, you must do so explicitly::
 
116
Note that the variables included in the cycle will not be escaped.
 
117
This is because template tags do not escape their content. Any HTML or
 
118
Javascript code contained in the printed variable will be rendered
 
119
as-is, which could potentially lead to security issues.
 
120
 
 
121
If you need to escape the variables in the cycle, you must do so
 
122
explicitly::
107
123
 
108
124
    {% filter force_escape %}
109
125
        {% cycle var1 var2 var3 %}
191
207
 
192
208
    {% firstof var1 var2 var3 "fallback value" %}
193
209
 
194
 
Note that the variables included in the firstof tag will not be escaped. This
195
 
is because template tags do not escape their content. If you want to escape
196
 
the variables in the firstof tag, you must do so explicitly::
 
210
Note that the variables included in the firstof tag will not be
 
211
escaped. This is because template tags do not escape their content.
 
212
Any HTML or Javascript code contained in the printed variable will be
 
213
rendered as-is, which could potentially lead to security issues.
 
214
 
 
215
If you need to escape the variables in the firstof tag, you must do so
 
216
explicitly::
197
217
 
198
218
    {% filter force_escape %}
199
219
        {% firstof var1 var2 var3 "fallback value" %}
301
321
As you can see, the ``if`` tag can take an optional ``{% else %}`` clause that
302
322
will be displayed if the test fails.
303
323
 
 
324
Boolean operators
 
325
^^^^^^^^^^^^^^^^^
 
326
 
304
327
``if`` tags may use ``and``, ``or`` or ``not`` to test a number of variables or
305
328
to negate a given variable::
306
329
 
326
349
        There are some athletes and absolutely no coaches.
327
350
    {% endif %}
328
351
 
329
 
``if`` tags don't allow ``and`` and ``or`` clauses within the same tag, because
330
 
the order of logic would be ambiguous. For example, this is invalid::
 
352
.. versionchanged:: 1.2
 
353
 
 
354
Use of both ``and`` and ``or`` clauses within the same tag is allowed, with
 
355
``and`` having higher precedence than ``or`` e.g.::
331
356
 
332
357
    {% if athlete_list and coach_list or cheerleader_list %}
333
358
 
334
 
If you need to combine ``and`` and ``or`` to do advanced logic, just use nested
335
 
``if`` tags. For example::
336
 
 
337
 
    {% if athlete_list %}
338
 
        {% if coach_list or cheerleader_list %}
339
 
            We have athletes, and either coaches or cheerleaders!
340
 
        {% endif %}
341
 
    {% endif %}
342
 
 
343
 
Multiple uses of the same logical operator are fine, as long as you use the
344
 
same operator. For example, this is valid::
345
 
 
346
 
    {% if athlete_list or coach_list or parent_list or teacher_list %}
 
359
will be interpreted like:
 
360
 
 
361
.. code-block:: python
 
362
 
 
363
    if (athlete_list and coach_list) or cheerleader_list
 
364
 
 
365
Use of actual brackets in the ``if`` tag is invalid syntax.  If you need them to
 
366
indicate precedence, you should use nested ``if`` tags.
 
367
 
 
368
.. versionadded:: 1.2
 
369
 
 
370
 
 
371
``if`` tags may also use the operators ``==``, ``!=``, ``<``, ``>``,
 
372
``<=``, ``>=`` and ``in`` which work as follows:
 
373
 
 
374
 
 
375
``==`` operator
 
376
^^^^^^^^^^^^^^^
 
377
 
 
378
Equality. Example::
 
379
 
 
380
    {% if somevar == "x" %}
 
381
      This appears if variable somevar equals the string "x"
 
382
    {% endif %}
 
383
 
 
384
``!=`` operator
 
385
^^^^^^^^^^^^^^^
 
386
 
 
387
Inequality. Example::
 
388
 
 
389
    {% if somevar != "x" %}
 
390
      This appears if variable somevar does not equal the string "x",
 
391
      or if somevar is not found in the context
 
392
    {% endif %}
 
393
 
 
394
``<`` operator
 
395
^^^^^^^^^^^^^^
 
396
 
 
397
Less than. Example::
 
398
 
 
399
    {% if somevar < 100 %}
 
400
      This appears if variable somevar is less than 100.
 
401
    {% endif %}
 
402
 
 
403
``>`` operator
 
404
^^^^^^^^^^^^^^
 
405
 
 
406
Greater than. Example::
 
407
 
 
408
    {% if somevar > 0 %}
 
409
      This appears if variable somevar is greater than 0.
 
410
    {% endif %}
 
411
 
 
412
``<=`` operator
 
413
^^^^^^^^^^^^^^^
 
414
 
 
415
Less than or equal to. Example::
 
416
 
 
417
    {% if somevar <= 100 %}
 
418
      This appears if variable somevar is less than 100 or equal to 100.
 
419
    {% endif %}
 
420
 
 
421
``>=`` operator
 
422
^^^^^^^^^^^^^^^
 
423
 
 
424
Greater than or equal to. Example::
 
425
 
 
426
    {% if somevar >= 1 %}
 
427
      This appears if variable somevar is greater than 1 or equal to 1.
 
428
    {% endif %}
 
429
 
 
430
``in`` operator
 
431
^^^^^^^^^^^^^^^
 
432
 
 
433
Contained within. This operator is supported by many Python containers to test
 
434
whether the given value is in the container.  The following are some examples of
 
435
how ``x in y`` will be interpreted::
 
436
 
 
437
    {% if "bc" in "abcdef" %}
 
438
      This appears since "bc" is a substring of "abcdef"
 
439
    {% endif %}
 
440
 
 
441
    {% if "hello" in greetings %}
 
442
      If greetings is a list or set, one element of which is the string
 
443
      "hello", this will appear.
 
444
    {% endif %}
 
445
 
 
446
    {% if user in users %}
 
447
      If users is a QuerySet, this will appear if user is an
 
448
      instance that belongs to the QuerySet.
 
449
    {% endif %}
 
450
 
 
451
``not in`` operator
 
452
~~~~~~~~~~~~~~~~~~~~
 
453
 
 
454
Not contained within.  This is the negation of the ``in`` operator.
 
455
 
 
456
 
 
457
The comparison operators cannot be 'chained' like in Python or in mathematical
 
458
notation. For example, instead of using::
 
459
 
 
460
    {% if a > b > c %}  (WRONG)
 
461
 
 
462
you should use::
 
463
 
 
464
    {% if a > b and b > c %}
 
465
 
 
466
 
 
467
Filters
 
468
^^^^^^^
 
469
 
 
470
You can also use filters in the ``if`` expression. For example::
 
471
 
 
472
    {% if messages|length >= 100 %}
 
473
       You have lots of messages today!
 
474
    {% endif %}
 
475
 
 
476
Complex expressions
 
477
^^^^^^^^^^^^^^^^^^^
 
478
 
 
479
All of the above can be combined to form complex expressions. For such
 
480
expressions, it can be important to know how the operators are grouped when the
 
481
expression is evaluated - that is, the precedence rules.  The precedence of the
 
482
operators, from lowest to highest, is as follows:
 
483
 
 
484
 * ``or``
 
485
 * ``and``
 
486
 * ``not``
 
487
 * ``in``
 
488
 * ``==``, ``!=``, ``<``, ``>``,``<=``, ``>=``
 
489
 
 
490
(This follows Python exactly). So, for example, the following complex if tag:
 
491
 
 
492
    {% if a == b or c == d and e %}
 
493
 
 
494
...will be interpreted as:
 
495
 
 
496
.. code-block:: python
 
497
 
 
498
    (a == b) or ((c == d) and e)
 
499
 
 
500
If you need different precedence, you will need to use nested if tags. Sometimes
 
501
that is better for clarity anyway, for the sake of those who do not know the
 
502
precedence rules.
 
503
 
347
504
 
348
505
.. templatetag:: ifchanged
349
506
 
415
572
``False``.  If you need to test if something is true or false, use the ``if``
416
573
tag instead.
417
574
 
 
575
.. versionadded:: 1.2
 
576
   An alternative to the ``ifequal`` tag is to use the :ttag:`if` tag and the ``==`` operator.
 
577
 
418
578
.. templatetag:: ifnotequal
419
579
 
420
580
ifnotequal
422
582
 
423
583
Just like ``ifequal``, except it tests that the two arguments are not equal.
424
584
 
 
585
.. versionadded:: 1.2
 
586
   An alternative to the ``ifnotequal`` tag is to use the :ttag:`if` tag and the ``!=`` operator.
 
587
 
425
588
.. templatetag:: include
426
589
 
427
590
include
456
619
 
457
620
See also: ``{% ssi %}``.
458
621
 
 
622
.. note::
 
623
    The :ttag:`include` tag should be considered as an implementation of
 
624
    "render this subtemplate and include the HTML", not as "parse this
 
625
    subtemplate and include its contents as if it were part of the parent".
 
626
    This means that there is no shared state between included templates --
 
627
    each include is a completely independent rendering process.
 
628
 
459
629
.. templatetag:: load
460
630
 
461
631
load
487
657
    A                 ``'AM'`` or ``'PM'``.                     ``'AM'``
488
658
    b                 Month, textual, 3 letters, lowercase.     ``'jan'``
489
659
    B                 Not implemented.
 
660
    c                 ISO 8601 Format.                          ``2008-01-02T10:30:00.000123``
490
661
    d                 Day of the month, 2 digits with           ``'01'`` to ``'31'``
491
662
                      leading zeros.
492
663
    D                 Day of the week, textual, 3 letters.      ``'Fri'``
523
694
                      month, 2 characters.
524
695
    t                 Number of days in the given month.        ``28`` to ``31``
525
696
    T                 Time zone of this machine.                ``'EST'``, ``'MDT'``
 
697
    u                 Microseconds.                             ``0`` to ``999999``
526
698
    U                 Seconds since the Unix Epoch
527
699
                      (January 1 1970 00:00:00 UTC).
528
700
    w                 Day of the week, digits without           ``'0'`` (Sunday) to ``'6'`` (Saturday)
551
723
 
552
724
This would display as "It is the 4th of September".
553
725
 
 
726
.. versionadded:: 1.2
 
727
 
 
728
The ``c`` and ``u`` format specification characters were added in Django 1.2.
 
729
 
554
730
.. templatetag:: regroup
555
731
 
556
732
regroup
739
915
view function and optional parameters. This is a way to output links without
740
916
violating the DRY principle by having to hard-code URLs in your templates::
741
917
 
742
 
    {% url path.to.some_view arg1,arg2,name1=value1 %}
 
918
    {% url path.to.some_view v1 v2 %}
743
919
 
744
920
The first argument is a path to a view function in the format
745
921
``package.package.module.function``. Additional arguments are optional and
746
 
should be comma-separated values that will be used as positional and keyword
747
 
arguments in the URL. All arguments required by the URLconf should be present.
 
922
should be space-separated values that will be used as arguments in the URL.
 
923
The example above shows passing positional arguments. Alternatively you may
 
924
use keyword syntax::
 
925
 
 
926
    {% url path.to.some_view arg1=v1 arg2=v2 %}
 
927
 
 
928
Do not mix both positional and keyword syntax in a single call. All arguments
 
929
required by the URLconf should be present.
748
930
 
749
931
For example, suppose you have a view, ``app_views.client``, whose URLconf
750
932
takes a client ID (here, ``client()`` is a method inside the views file
783
965
different call::
784
966
 
785
967
 
786
 
    {% url path.to.view arg, arg2 as the_url %}
 
968
    {% url path.to.view arg arg2 as the_url %}
787
969
 
788
970
    <a href="{{ the_url }}">I'm linking to {{ the_url }}</a>
789
971
 
805
987
<topics-http-reversing-url-namespaces>`, including using any hints provided
806
988
by the context as to the current application.
807
989
 
 
990
.. versionchanged:: 1.2
 
991
 
 
992
For backwards compatibility, the ``{% url %}`` tag also supports the
 
993
use of commas to separate arguments. You shouldn't use this in any new
 
994
projects, but for the sake of the people who are still using it,
 
995
here's what it looks like::
 
996
 
 
997
    {% url path.to.view arg,arg2 %}
 
998
    {% url path.to.view arg, arg2 %}
 
999
 
 
1000
This syntax doesn't support the use of literal commas, or or equals
 
1001
signs. Did we mention you shouldn't use this syntax in any new
 
1002
projects?
 
1003
 
808
1004
.. templatetag:: widthratio
809
1005
 
810
1006
widthratio
858
1054
 
859
1055
If ``value`` is ``4``, then the output will be ``6``.
860
1056
 
 
1057
.. versionchanged:: 1.2
 
1058
   The following behavior didn't exist in previous Django versions.
 
1059
 
 
1060
This filter will first try to coerce both values to integers. If this fails,
 
1061
it'll attempt to add the values together anyway. This will work on some data
 
1062
types (strings, list, etc.) and fail on others. If it fails, the result will
 
1063
be an empty string.
 
1064
 
 
1065
For example, if we have::
 
1066
 
 
1067
    {{ first|add:second }}
 
1068
 
 
1069
and ``first`` is ``[1, 2, 3]`` and ``second`` is ``[4, 5, 6]``, then the
 
1070
output will be ``[1, 2, 3, 4, 5, 6]``.
 
1071
 
 
1072
.. warning::
 
1073
 
 
1074
    Keep in mind that strings that can both be coerced to integers will be,
 
1075
    and thus will be will be *summed*, not concatenated, as in the first
 
1076
    example above.
 
1077
 
861
1078
.. templatefilter:: addslashes
862
1079
 
863
1080
addslashes
865
1082
 
866
1083
Adds slashes before quotes. Useful for escaping strings in CSV, for example.
867
1084
 
 
1085
For example::
 
1086
 
 
1087
    {{ value|addslashes }}
 
1088
 
 
1089
If ``value`` is ``"I'm using Django"``, the output will be ``"I\'m using Django"``.
 
1090
 
868
1091
.. templatefilter:: capfirst
869
1092
 
870
1093
capfirst
872
1095
 
873
1096
Capitalizes the first character of the value.
874
1097
 
 
1098
For example::
 
1099
 
 
1100
    {{ value|capfirst }}
 
1101
 
 
1102
If ``value`` is ``"django"``, the output will be ``"Django"``.
 
1103
 
875
1104
.. templatefilter:: center
876
1105
 
877
1106
center
879
1108
 
880
1109
Centers the value in a field of a given width.
881
1110
 
 
1111
For example::
 
1112
 
 
1113
    "{{ value|center:"15" }}"
 
1114
 
 
1115
If ``value`` is ``"Django"``, the output will be ``"     Django    "``.
 
1116
 
882
1117
.. templatefilter:: cut
883
1118
 
884
1119
cut
897
1132
date
898
1133
~~~~
899
1134
 
900
 
Formats a date according to the given format (same as the `now`_ tag).
 
1135
Formats a date according to the given format.
 
1136
 
 
1137
Given format can be one of the predefined ones ``DATE_FORMAT``,
 
1138
``DATETIME_FORMAT``, ``SHORT_DATE_FORMAT`` or ``SHORT_DATETIME_FORMAT``,
 
1139
or a custom format, same as the :ttag:`now` tag. Note that predefined formats
 
1140
may vary depending on the current locale.
901
1141
 
902
1142
For example::
903
1143
 
907
1147
``datetime.datetime.now()``), the output will be the string
908
1148
``'Wed 09 Jan 2008'``.
909
1149
 
 
1150
Another example:
 
1151
 
 
1152
Assuming that :setting:`USE_L10N` is ``True`` and :setting:`LANGUAGE_CODE` is,
 
1153
for example, ``"es"``, then for::
 
1154
 
 
1155
    {{ value|date:"SHORT_DATE_FORMAT" }}
 
1156
 
 
1157
the output will be the string ``"09/01/2008"`` (The ``"SHORT_DATE_FORMAT"``
 
1158
format specifier for the ``es`` locale as shipped with Django is ``"d/m/Y"``).
 
1159
 
910
1160
When used without a format string::
911
1161
 
912
1162
    {{ value|date }}
913
1163
 
914
1164
...the formatting string defined in the :setting:`DATE_FORMAT` setting will be
915
 
used.
 
1165
used, without applying any localization.
 
1166
 
 
1167
.. versionchanged:: 1.2
 
1168
    Predefined formats can now be influenced by the current locale.
916
1169
 
917
1170
.. templatefilter:: default
918
1171
 
1037
1290
string safe for use in HTML, but does protect you from syntax errors when using
1038
1291
templates to generate JavaScript/JSON.
1039
1292
 
 
1293
For example::
 
1294
 
 
1295
    {{ value|escapejs }}
 
1296
 
 
1297
If ``value`` is ``"testing\r\njavascript \'string" <b>escaping</b>"``,
 
1298
the output will be ``"testing\\u000D\\u000Ajavascript \\u0027string\\u0022 \\u003Cb\\u003Eescaping\\u003C/b\\u003E"``.
 
1299
 
1040
1300
.. templatefilter:: filesizeformat
1041
1301
 
1042
1302
filesizeformat
1151
1411
 
1152
1412
If ``value`` is ``123456789``, the output will be ``8``.
1153
1413
 
1154
 
.. templatefilter:: iriendcode
 
1414
.. templatefilter:: iriencode
1155
1415
 
1156
1416
iriencode
1157
1417
~~~~~~~~~
1163
1423
It's safe to use this filter on a string that has already gone through the
1164
1424
``urlencode`` filter.
1165
1425
 
 
1426
For example::
 
1427
 
 
1428
    {{ value|iriencode }}
 
1429
 
 
1430
If ``value`` is ``"?test=1&me=2"``, the output will be ``"?test=1&amp;me=2"``.
 
1431
 
1166
1432
.. templatefilter:: join
1167
1433
 
1168
1434
join
1243
1509
Converts all newlines in a piece of plain text to HTML line breaks
1244
1510
(``<br />``).
1245
1511
 
 
1512
For example::
 
1513
 
 
1514
    {{ value|linebreaksbr }}
 
1515
 
 
1516
If ``value`` is ``Joel\nis a slug``, the output will be ``Joel<br />is a
 
1517
slug``.
 
1518
 
1246
1519
.. templatefilter:: linenumbers
1247
1520
 
1248
1521
linenumbers
1250
1523
 
1251
1524
Displays text with line numbers.
1252
1525
 
 
1526
For example::
 
1527
 
 
1528
    {{ value|linenumbers }}
 
1529
 
 
1530
If ``value`` is::
 
1531
 
 
1532
    one
 
1533
    two
 
1534
    three
 
1535
 
 
1536
the output will be::
 
1537
 
 
1538
    1. one
 
1539
    2. two
 
1540
    3. three
 
1541
 
1253
1542
.. templatefilter:: ljust
1254
1543
 
1255
1544
ljust
1259
1548
 
1260
1549
**Argument:** field size
1261
1550
 
 
1551
For example::
 
1552
 
 
1553
    "{{ value|ljust:"10" }}"
 
1554
 
 
1555
If ``value`` is ``Django``, the output will be ``"Django    "``.
 
1556
 
1262
1557
.. templatefilter:: lower
1263
1558
 
1264
1559
lower
1294
1589
~~~~~~~~~~~~~
1295
1590
 
1296
1591
Converts a phone number (possibly containing letters) to its numerical
1297
 
equivalent. For example, ``'800-COLLECT'`` will be converted to
1298
 
``'800-2655328'``.
 
1592
equivalent.
1299
1593
 
1300
1594
The input doesn't have to be a valid phone number. This will happily convert
1301
1595
any string.
1302
1596
 
 
1597
For example::
 
1598
 
 
1599
    {{ value|phone2numeric }}
 
1600
 
 
1601
If ``value`` is ``800-COLLECT``, the output will be ``800-2655328``.
 
1602
 
1303
1603
.. templatefilter:: pluralize
1304
1604
 
1305
1605
pluralize
1311
1611
 
1312
1612
    You have {{ num_messages }} message{{ num_messages|pluralize }}.
1313
1613
 
 
1614
If ``num_messages`` is ``1``, the output will be ``You have 1 message.``
 
1615
If ``num_messages`` is ``2``  the output will be ``You have 2 messages.``
 
1616
 
1314
1617
For words that require a suffix other than ``'s'``, you can provide an alternate
1315
1618
suffix as a parameter to the filter.
1316
1619
 
1370
1673
 
1371
1674
**Argument:** field size
1372
1675
 
 
1676
For example::
 
1677
 
 
1678
    "{{ value|rjust:"10" }}"
 
1679
 
 
1680
If ``value`` is ``Django``, the output will be ``"    Django"``.
 
1681
 
1373
1682
.. templatefilter:: safe
1374
1683
 
1375
1684
safe
1378
1687
Marks a string as not requiring further HTML escaping prior to output. When
1379
1688
autoescaping is off, this filter has no effect.
1380
1689
 
 
1690
.. note::
 
1691
 
 
1692
    If you are chaining filters, a filter applied after ``safe`` can
 
1693
    make the contents unsafe again. For example, the following code
 
1694
    prints the variable as is, unescaped:
 
1695
 
 
1696
    .. code-block:: html+django
 
1697
 
 
1698
        {{ var|safe|escape }}
 
1699
 
1381
1700
.. templatefilter:: safeseq
1382
1701
 
1383
1702
safeseq
1408
1727
 
1409
1728
    {{ some_list|slice:":2" }}
1410
1729
 
 
1730
If ``some_list`` is ``['a', 'b', 'c']``, the output will be ``['a', 'b']``.
 
1731
 
1411
1732
.. templatefilter:: slugify
1412
1733
 
1413
1734
slugify
1460
1781
time
1461
1782
~~~~
1462
1783
 
1463
 
Formats a time according to the given format (same as the `now`_ tag).
 
1784
Formats a time according to the given format.
 
1785
 
 
1786
Given format can be the predefined one ``TIME_FORMAT``, or a custom format,
 
1787
same as the :ttag:`now` tag. Note that the predefined format is locale-
 
1788
dependant.
 
1789
 
1464
1790
The time filter will only accept parameters in the format string that relate
1465
1791
to the time of day, not the date (for obvious reasons). If you need to
1466
 
format a date, use the `date`_ filter.
 
1792
format a date, use the :tfilter:`date` filter.
1467
1793
 
1468
1794
For example::
1469
1795
 
1472
1798
If ``value`` is equivalent to ``datetime.datetime.now()``, the output will be
1473
1799
the string ``"01:23"``.
1474
1800
 
 
1801
Another example:
 
1802
 
 
1803
Assuming that :setting:`USE_L10N` is ``True`` and :setting:`LANGUAGE_CODE` is,
 
1804
for example, ``"de"``, then for::
 
1805
 
 
1806
    {{ value|time:"TIME_FORMAT" }}
 
1807
 
 
1808
the output will be the string ``"01:23:00"`` (The ``"TIME_FORMAT"`` format
 
1809
specifier for the ``de`` locale as shipped with Django is ``"H:i:s"``).
 
1810
 
1475
1811
When used without a format string::
1476
1812
 
1477
1813
    {{ value|time }}
1478
1814
 
1479
1815
...the formatting string defined in the :setting:`TIME_FORMAT` setting will be
1480
 
used.
 
1816
used, without applying any localization.
 
1817
 
 
1818
.. versionchanged:: 1.2
 
1819
    Predefined formats can now be influenced by the current locale.
1481
1820
 
1482
1821
.. templatefilter:: timesince
1483
1822
 
1523
1862
 
1524
1863
Converts a string into titlecase.
1525
1864
 
 
1865
For example::
 
1866
 
 
1867
    {{ value|title }}
 
1868
 
 
1869
If ``value`` is ``"my first post"``, the output will be ``"My First Post"``.
 
1870
 
1526
1871
.. templatefilter:: truncatewords
1527
1872
 
1528
1873
truncatewords
1550
1895
This is less efficient than ``truncatewords``, so should only be used when it
1551
1896
is being passed HTML text.
1552
1897
 
 
1898
For example::
 
1899
 
 
1900
    {{ value|truncatewords_html:2 }}
 
1901
 
 
1902
If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be
 
1903
``"<p>Joel is ...</p>"``.
 
1904
 
1553
1905
.. templatefilter:: unordered_list
1554
1906
 
1555
1907
unordered_list
1600
1952
 
1601
1953
Escapes a value for use in a URL.
1602
1954
 
 
1955
For example::
 
1956
 
 
1957
    {{ value|urlencode }}
 
1958
 
 
1959
If ``value`` is ``"http://www.example.org/foo?a=b&c=d"``, the output will be
 
1960
``"http%3A//www.example.org/foo%3Fa%3Db%26c%3Dd"``.
 
1961
 
1603
1962
.. templatefilter:: urlize
1604
1963
 
1605
1964
urlize
1645
2004
 
1646
2005
Returns the number of words.
1647
2006
 
 
2007
For example::
 
2008
 
 
2009
    {{ value|wordcount }}
 
2010
 
 
2011
If ``value`` is ``"Joel is a slug"``, the output will be ``4``.
 
2012
 
1648
2013
.. templatefilter:: wordwrap
1649
2014
 
1650
2015
wordwrap
1711
2076
 
1712
2077
A collection of template tags that can be useful while designing a website,
1713
2078
such as a generator of Lorem Ipsum text. See :ref:`ref-contrib-webdesign`.
 
2079
 
 
2080
i18n
 
2081
~~~~
 
2082
 
 
2083
Provides a couple of templatetags that allow specifying translatable text in
 
2084
Django templates. It is slightly different from the libraries described
 
2085
above because you don't need to add any application to the ``INSTALLED_APPS``
 
2086
setting but rather set :setting:`USE_I18N` to True, then loading it with
 
2087
``{% load i18n %}``. See :ref:`specifying-translation-strings-in-template-code`.