Django

Code

Changeset 7280

Show
Ignore:
Timestamp:
03/17/08 23:21:08 (6 months ago)
Author:
adrian
Message:

Edited docs/templates.txt changes from [7276]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/templates.txt

    r7276 r7280  
    12231223~~~ 
    12241224 
    1225 Adds the arg to the value. 
    1226  
    1227 For example:: 
    1228  
    1229     {{ value|add:2 }} 
    1230  
    1231 If ``value`` is 4, then the output will be 6
     1225Adds the argument to the value. 
     1226 
     1227For example:: 
     1228 
     1229    {{ value|add:"2" }} 
     1230 
     1231If ``value`` is ``4``, then the output will be ``6``
    12321232 
    12331233addslashes 
     
    12361236Adds slashes before quotes. Useful for escaping strings in CSV, for example. 
    12371237 
    1238 **New in Django development version**: for escaping data in JavaScript strings, 
     1238**New in Django development version**: For escaping data in JavaScript strings, 
    12391239use the `escapejs`_ filter instead. 
    12401240 
     
    12581258    {{ value|cut:" "}} 
    12591259 
    1260 If ``value`` is "String with spaces", the output will be ``Stringwithspaces``. 
     1260If ``value`` is ``"String with spaces"``, the output will be ``"Stringwithspaces"``. 
    12611261 
    12621262date 
     
    12691269    {{ value|date:"D d M Y" }} 
    12701270 
    1271 If ``value`` is a datetime object (ie. datetime.datetime.now()), the output 
    1272 would be formatted like ``Wed 09 Jan 2008``. 
     1271If ``value`` is a ``datetime`` object (e.g., the result of 
     1272``datetime.datetime.now()``), the output will be the string 
     1273``'Wed 09 Jan 2008'``. 
    12731274 
    12741275default 
    12751276~~~~~~~ 
    12761277 
    1277 If value is unavailable, use given default
     1278If value evaluates to ``False``, use given default. Otherwise, use the value
    12781279 
    12791280For example:: 
     
    12811282    {{ value|default:"nothing" }} 
    12821283 
    1283 If ``value`` is ``Undefined``, the output would be ``nothing``. 
     1284If ``value`` is ``""`` (the empty string), the output will be ``nothing``. 
    12841285 
    12851286default_if_none 
    12861287~~~~~~~~~~~~~~~ 
    12871288 
    1288 If value is ``None``, use given default. 
     1289If (and only if) value is ``None``, use given default. Otherwise, use the 
     1290value. 
     1291 
     1292Note that if an empty string is given, the default value will *not* be used. 
     1293Use the ``default`` filter if you want to fallback for empty strings. 
    12891294 
    12901295For example:: 
     
    12921297    {{ value|default_if_none:"nothing" }} 
    12931298 
    1294 If ``value`` is ``None``, the output would be ``nothing``. 
     1299If ``value`` is ``None``, the output will be the string ``"nothing"``. 
    12951300 
    12961301dictsort 
    12971302~~~~~~~~ 
    12981303 
    1299 Takes a list of dictionaries, returns that list sorted by the key given in 
     1304Takes a list of dictionaries and returns that list sorted by the key given in 
    13001305the argument. 
    13011306 
     
    13051310 
    13061311If ``value`` is:: 
    1307      
     1312 
    13081313    [ 
    1309         {'name': 'zed', 'age': 19} 
    1310         {'name': 'amy', 'age': 22},  
    1311         {'name': 'joe', 'age': 31},  
     1314        {'name': 'zed', 'age': 19}, 
     1315        {'name': 'amy', 'age': 22}, 
     1316        {'name': 'joe', 'age': 31}, 
    13121317    ] 
    13131318 
     
    13151320 
    13161321    [ 
    1317         {'name': 'amy', 'age': 22},  
    1318         {'name': 'joe', 'age': 31},  
    1319         {'name': 'zed', 'age': 19} 
     1322        {'name': 'amy', 'age': 22}, 
     1323        {'name': 'joe', 'age': 31}, 
     1324        {'name': 'zed', 'age': 19}, 
    13201325    ] 
    13211326 
     
    13231328~~~~~~~~~~~~~~~~ 
    13241329 
    1325 Takes a list of dictionaries, returns that list sorted in reverse order by the 
    1326 key given in the argument. This works exactly the same as the above filter, but 
    1327 the returned value will be in reverse order. 
     1330Takes a list of dictionaries and returns that list sorted in reverse order by 
     1331the key given in the argument. This works exactly the same as the above filter, 
     1332but the returned value will be in reverse order. 
    13281333 
    13291334divisibleby 
    13301335~~~~~~~~~~~ 
    13311336 
    1332 Returns true if the value is divisible by the argument. 
    1333  
    1334 For example:: 
    1335  
    1336     {{ value|divisibleby:3 }} 
     1337Returns ``True`` if the value is divisible by the argument. 
     1338 
     1339For example:: 
     1340 
     1341    {{ value|divisibleby:"3" }} 
    13371342 
    13381343If ``value`` is ``21``, the output would be ``True``. 
     
    13401345escape 
    13411346~~~~~~ 
    1342  
    1343 **New in Django development version:** The behaviour of this filter has 
    1344 changed slightly in the development version (the affects are only applied 
    1345 once, after all other filters). 
    13461347 
    13471348Escapes a string's HTML. Specifically, it makes these replacements: 
     
    13631364multiple escaping passes to be applied, use the ``force_escape`` filter. 
    13641365 
     1366**New in Django development version:** Due to auto-escaping, the behavior of 
     1367this filter has changed slightly. The replacements are only made once, after 
     1368all other filters are applied -- including filters before and after it. 
     1369 
    13651370escapejs 
    13661371~~~~~~~~ 
     
    13931398    {{ value|first }} 
    13941399 
    1395 If ``value`` is ``['a', 'b', 'c']``, the output would be `a`. 
     1400If ``value`` is the list ``['a', 'b', 'c']``, the output will be ``'a'``. 
    13961401 
    13971402fix_ampersands 
     
    14041409    {{ value|fix_ampersands }} 
    14051410 
    1406 If ``value`` is ``Tom & Jerry``, the output would be ``Tom & Jerry``. 
    1407  
    1408 **New in Django development version**: you probably don't need to use this 
    1409 filter since ampersands will be automatically escaped. See escape_ for more on 
    1410 how auto-escaping works. 
     1411If ``value`` is ``Tom & Jerry``, the output will be ``Tom & Jerry``. 
     1412 
     1413**New in Django development version**: This filter generally is no longer 
     1414useful, because ampersands are automatically escaped in templates. See escape_ 
     1415for more on how auto-escaping works. 
    14111416 
    14121417floatformat 
     
    14641469~~~~~~~~~ 
    14651470 
    1466 Given a whole number, returns the requested digit of it, where 1 is the 
    1467 right-most digit, 2 is the second-right-most digit, etc. Returns the original 
    1468 value for invalid input (if input or argument is not an integer, or if argument 
    1469 is less than 1). Otherwise, output is always an integer. 
    1470  
    1471 For example:: 
    1472      
    1473     {{ value|get_digit:2 }} 
    1474  
    1475 If ``value`` is 123456789, the output would be ``8``. 
     1471Given a whole number, returns the requested digit, where 1 is the right-most 
     1472digit, 2 is the second-right-most digit, etc. Returns the original value for 
     1473invalid input (if input or argument is not an integer, or if argument is less 
     1474than 1). Otherwise, output is always an integer. 
     1475 
     1476For example:: 
     1477 
     1478    {{ value|get_digit:"2" }} 
     1479 
     1480If ``value`` is ``123456789``, the output will be ``8``. 
    14761481 
    14771482iriencode 
     
    14941499    {{ value|join:" // " }} 
    14951500 
    1496 If ``value`` is ``['a', 'b', 'c']``, the output would be ``a // b // c``. 
     1501If ``value`` is the list ``['a', 'b', 'c']``, the output will be the string 
     1502``"a // b // c"``. 
    14971503 
    14981504last 
     
    15071513    {{ value|last }} 
    15081514 
    1509 If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``d``. 
     1515If ``value`` is the list ``['a', 'b', 'c', 'd']``, the output will be the string 
     1516``"d"``. 
    15101517 
    15111518length 
    15121519~~~~~~ 
    15131520 
    1514 Returns the length of the value. Useful for lists. 
     1521Returns the length of the value. This works for both strings and lists. 
    15151522 
    15161523For example:: 
     
    15181525    {{ value|length }} 
    15191526 
    1520 If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``4``. 
     1527If ``value`` is ``['a', 'b', 'c', 'd']``, the output will be ``4``. 
    15211528 
    15221529length_is 
    15231530~~~~~~~~~ 
    15241531 
    1525 Returns a boolean of whether the value's length is the argument
    1526  
    1527 For example:: 
    1528  
    1529     {{ value|length_is:4 }} 
    1530  
    1531 If ``value`` is ``['a', 'b', 'c', 'd']``, the output would be ``True``. 
     1532Returns ``True`` if the value's length is the argument, or ``False`` otherwise
     1533 
     1534For example:: 
     1535 
     1536    {{ value|length_is:"4" }} 
     1537 
     1538If ``value`` is ``['a', 'b', 'c', 'd']``, the output will be ``True``. 
    15321539 
    15331540linebreaks 
     
    15421549    {{ value|linebreaks }} 
    15431550 
    1544 If ``value`` is ``Joel\nis a slug``, the output would be ``<p>Joe<br>is a 
     1551If ``value`` is ``Joel\nis a slug``, the output will be ``<p>Joe<br>is a 
    15451552slug</p>``. 
    15461553 
     
    15721579    {{ value|lower }} 
    15731580 
    1574 If ``value`` is ``Joel Is a Slug``, the output would be ``joel is a slug``. 
     1581If ``value`` is ``Still MAD At Yoko``, the output will be ``still mad at yoko``. 
    15751582 
    15761583make_list 
     
    15841591    {{ value|make_list }} 
    15851592 
    1586 If ``value`` is "Joe", the output would be ``[u'J', u'o', u'e']. If ``value`` is 
    1587 123, the output would be ``[1, 2, 3]``. 
     1593If ``value`` is the string ``"Joe"``, the output would be the list 
     1594``[u'J', u'o', u'e']``. If ``value`` is ``123``, the output will be the list 
     1595``[1, 2, 3]``. 
    15881596 
    15891597phone2numeric 
     
    16301638~~~~~~ 
    16311639 
    1632 Returns a random item from the list. 
     1640Returns a random item from the given list. 
    16331641 
    16341642For example:: 
     
    16361644    {{ value|random }} 
    16371645 
    1638 If ``value`` is ``['a', 'b', 'c', 'd']``, the output could be ``b``. 
     1646If ``value`` is the list ``['a', 'b', 'c', 'd']``, the output could be ``"b"``. 
    16391647 
    16401648removetags 
    16411649~~~~~~~~~~ 
    16421650 
    1643 Removes a space separated list of [X]HTML tags from the output. 
     1651Removes a space-separated list of [X]HTML tags from the output. 
    16441652 
    16451653For example:: 
     
    16471655    {{ value|removetags:"b span"|safe }} 
    16481656 
    1649 If ``value`` is ``<b>Joel</b> <button>is</button> a <span>slug</span>`` the 
    1650 output would be ``Joel <button>is</button> a slug``. 
     1657If ``value`` is ``"<b>Joel</b> <button>is</button> a <span>slug</span>"`` the 
     1658output will be ``"Joel <button>is</button> a slug"``. 
    16511659 
    16521660rjust 
     
    16851693    {{ value|slugify }} 
    16861694 
    1687 If ``value`` is ``Joel is a slug``, the output would be ``joel-is-a-slug``. 
     1695If ``value`` is ``"Joel is a slug"``, the output will be ``"joel-is-a-slug"``. 
    16881696 
    16891697stringformat 
     
    17011709    {{ value|stringformat:"s" }} 
    17021710 
    1703 If ``value`` is ``Joel is a slug``, the output would be ``Joel is a slug``. 
     1711If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is a slug"``. 
    17041712 
    17051713striptags 
     
    17121720    {{ value|striptags }} 
    17131721 
    1714 If ``value`` is ``<b>Joel</b> <button>is</button> a <span>slug</span>`` the 
    1715 output would be ``Joel is a slug``. 
     1722If ``value`` is ``"<b>Joel</b> <button>is</button> a <span>slug</span>"``, the 
     1723output will be ``"Joel is a slug"``. 
    17161724 
    17171725time 
     
    17271735    {{ value|time:"H:i" }} 
    17281736 
    1729 If ``value`` is ``datetime.datetime.now()``, the output would be formatted 
    1730 like ``01:23``. 
     1737If ``value`` is equivalent to ``datetime.datetime.now()``, the output will be 
     1738the string ``"01:23"``. 
    17311739 
    17321740timesince 
    17331741~~~~~~~~~ 
    17341742 
    1735 Formats a date as the time since that date (i.e. "4 days, 6 hours"). 
     1743Formats a date as the time since that date (e.g., "4 days, 6 hours"). 
    17361744 
    17371745Takes an optional argument that is a variable containing the date to use as 
     
    17751783    {{ value|truncatewords:2 }} 
    17761784 
    1777 If ``value`` is ``Joel is a slug``, the output would be ``Joel is ...``. 
     1785If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is ..."``. 
    17781786 
    17791787truncatewords_html 
     
    17931801WITHOUT opening and closing <ul> tags. 
    17941802 
    1795 **Changed in Django development version** 
    1796  
    1797 The format accepted by ``unordered_list`` has changed to an easier to 
    1798 understand format. 
     1803**New in Django development version:** The format accepted by 
     1804``unordered_list`` has changed to be easier to understand. 
    17991805 
    18001806The list is assumed to be in the proper format. For example, if ``var`` contains 
     
    18261832    {{ value|upper }} 
    18271833 
    1828 If ``value`` is ``Joel is a slug``, the output would be ``JOEL IS A SLUG``. 
     1834If ``value`` is ``"Joel is a slug"``, the output will be ``"JOEL IS A SLUG"``. 
    18291835 
    18301836urlencode 
     
    18451851    {{ value|urlize }} 
    18461852 
    1847 If ``value`` is ``Check out www.djangoproject.com``, the output would be 
    1848 ``Check out <a 
    1849 href="http://www.djangoproject.com">www.djangoproject.com</a>``. 
     1853If ``value`` is ``"Check out www.djangoproject.com"``, the output will be 
     1854``"Check out <a 
     1855href="http://www.djangoproject.com">www.djangoproject.com</a>"``. 
    18501856 
    18511857urlizetrunc 
     
    18631869    {{ value|urlizetrunc:15 }} 
    18641870 
    1865 If ``value`` is ``Check out www.djangoproject.com``, the output would be 
    1866 ``Check out <a 
    1867 href="http://www.djangoproject.com">www.djangopr...</a>``. 
     1871If ``value`` is ``"Check out www.djangoproject.com"``, the output would be 
     1872``'Check out <a 
     1873href="http://www.djangoproject.com">www.djangopr...</a>'``. 
    18681874 
    18691875wordcount