1024programmer Java Syntax of Djangotemplates templates

Syntax of Djangotemplates templates

  1. Variables
    {{ new_name }} ——》Variable Xinhua Publishing House Dictionary or list. Value
  2. The for loop for tag takes an optional {% empty %} clause to operate if the given group is empty or not found.
    {% for person in person_list %}

    {{ person.name }}

    # Loop through values ​​

    {% empty %}
         

    sorry,no person here

    # Displayed when person_list is empty {% endfor %}
  3. if tag: {% if %} will evaluate a variable. If its value is “True” (exists, is not empty, and is not a false value of boolean type), the corresponding content block will be output.
    {% if i > 300 %}

    Greater than {{ i }}

    {% elif i == 200 %}

    Equal to {{ i }}

    {% else %}

    Less than {{ i }}

    {% endif %}

  4. .with: Cache a complex variable using a simple name, very useful when you need to use an “expensive” method (such as accessing the database) many times
    {% with total=business.employees.count %}
    {{ total }} employee{{ total|pluralize }}
    {% endwith %}

    {{ person_list.2.name }}

    {% with name=person_list.2.name %}

    {{ name }}

    {% endwith %}

Django templates template syntax


This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/724844

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索