Django

Code

Changeset 6562

Show
Ignore:
Timestamp:
10/20/07 06:05:15 (11 months ago)
Author:
mtredinnick
Message:

Added a section to the template documentation to clarify the arbitrary Python
code should not be expected to work. The might help balance expectations.
Thanks, James Bennett. Fixed #5125.

Files:

Legend:

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

    r6533 r6562  
    1212or CheetahTemplate_, you should feel right at home with Django's templates. 
    1313 
     14.. admonition:: Philosophy 
     15 
     16    If you have a background in programming, or if you're used to languages 
     17    like PHP which mix programming code directly into HTML, you'll want to 
     18    bear in mind that the Django template system is not simply Python embedded 
     19    into HTML. This is by design: the template system is meant to express 
     20    presentation, not program logic. 
     21 
     22    The Django template system provides tags which function similarly to some 
     23    programming constructs -- an ``{% if %}`` tag for boolean tests, a ``{% 
     24    for %}`` tag for looping, etc. -- but these are not simply executed as the 
     25    corresponding Python code, and the template system will not execute 
     26    arbitrary Python expressions. Only the tags, filters and syntax listed 
     27    below are supported by default (although you can add `your own 
     28    extensions`_ to the template language as needed). 
     29 
    1430.. _`The Django template language: For Python programmers`: ../templates_python/ 
    1531.. _Smarty: http://smarty.php.net/ 
    1632.. _CheetahTemplate: http://www.cheetahtemplate.org/ 
     33.. _your own extensions: ../templates_python/#extending-the-template-system 
    1734 
    1835Templates 
     
    383400        </tr> 
    384401    {% endfor %} 
    385   
     402 
    386403Outside of a loop, give the values a unique name the first time you call it, 
    387404then use that name each successive time through:: 
     
    391408        <tr class="{% cycle rowcolors %}">...</tr> 
    392409 
    393 You can use any number of values, separated by spaces. Values enclosed in  
    394 single (') or double quotes (") are treated as string literals, while values  
    395 without quotes are assumed to refer to context variables.  
     410You can use any number of values, separated by spaces. Values enclosed in 
     411single (') or double quotes (") are treated as string literals, while values 
     412without quotes are assumed to refer to context variables. 
    396413 
    397414You can also separate values with commas:: 
    398415 
    399416    {% cycle row1,row2,row3 %} 
    400      
    401 In this syntax, each value will be interpreted as literal text. The  
    402 comma-based syntax exists for backwards-compatibility, and should not be  
     417 
     418In this syntax, each value will be interpreted as literal text. The 
     419comma-based syntax exists for backwards-compatibility, and should not be 
    403420used for new projects. 
    404421 
     
    478495in eachs sub-list into a set of known names. For example, if your context contains 
    479496a list of (x,y) coordinates called ``points``, you could use the following 
    480 to output the list of points::  
     497to output the list of points:: 
    481498 
    482499    {% for x, y in points %} 
    483500        There is a point at {{ x }},{{ y }} 
    484501    {% endfor %} 
    485      
    486 This can also be useful if you need to access the items in a dictionary.  
     502 
     503This can also be useful if you need to access the items in a dictionary. 
    487504For example, if your context contained a dictionary ``data``, the following 
    488505would display the keys and values of the dictionary::