DJANGO: Template

Source: Internet
Author: User

Templates are usually used to generate HTML, but Django templates can also generate any document based on text format.

The text enclosed in two braces (for example, {person_name}) is called a variable ).

The text enclosed by braces and percent signs (for example, {% if ordered_warranty %}) is a template tag ). Tags are clearly defined, that is, labels that only notify the template system to complete some work.

The template in this example contains a for tag ({% for item in item_list %}) and an if tag ({% if ordered_warranty % })

The for tag is similar to the for statement in Python, allowing you to access every project in the sequence cyclically. The IF tag, as expected, is used to perform logical judgment. Here, the tag label checks whether the value of ordered_warranty is true. If yes, the template System Displays content between {% ifordered_warranty %} and {% else %}; otherwise, content between {% else %} and {% endif %} is displayed. {% Else %} is optional.

Finally, the second section of the template contains an example of the filter, which is the most convenient way to convert the variable output format. For example, {ship_date | Date: "f j, Y"} in this example, we pass the variable ship_date to the date filter and specify the parameter "F ".J, y ". The date filter outputs the format based on parameters.

DJANGO: Template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.