目錄html
- 一 模板的組成
- 二 邏輯控制代碼的組成
- 變量使用雙大括號來引用變量
- 標籤tag的使用使用大括號和百分號組成來表示使用tag
- 過濾器filter的使用
- 三 經常使用標籤tag
- if
- ifequal 和 ifnotequal
- for
- cycle
- 註釋
- csrf_token
- debug
- filter
- autoescape
- firstof
- load
- now
- spaceless
- url
- verbatim
- with
- 四 經常使用過濾器filter
- add
- addslashes
- capfirst
- cut
- date
- default
- default_if_none
- dictsort
- dictsorted
- divisbleby
- escape
- escapejs
- filesizeformat
- first
- last
- floatformat
- length
- length_is
- urlencode
- upperlower
- safe
- slice
- time
- timesince
- truncatechars
- turncatewords
- striptags
- 五 文檔
{{ var_name }}
{% load staticfiles %}
{{ ship_date|date:"Fj,Y"}}
ship_date
變量傳給data過濾器,data過濾器經過使用Fj,Y
這幾個參數來格式化數據。|
表明相似Unix命令中的管道操做。{% if %}
{% ifequal %}
和{% ifnotequal %}
{% for %}
用來循環一個list,還可使用reserved關鍵字來進行倒序遍歷,通常能夠用if語句來西先判斷一下列表是否爲空,在進行遍歷;還可使用empty關鍵字來進行爲空時候的跳轉。python
**for標籤中可使用forloopdjango
forloop.counter: 當前循環計數,從1開始 forloop.counter0: 當前循環計數,從0開始 forloop.recounter: 當前循環倒數計數,從列表長度開始 forloop.recounter0: 當前循環倒數計數,從列表長度減1開始,標準 forloop.first: bool值,判斷是否是循環的第一個元素 forloop.last: bool值,判斷是否是循環的最後一個元素 forloop.parentloop: 用在嵌套循環中,獲得parent循環的引用,而後可使用以上參數
{% cycle %}
{# #}
單行註釋,{% comment %}
多行註釋{% csrf_token %}
{% debug %}
{% filter %}
{{% autoescape off %}} {{ value}} {{% endautoescape %}}
{% firstof %}
{% load %}
{% now %}
{% spaceless %}
{% url %}
{% verbatim %}
{% with %}
{{ value|add:"2" }} # 空格不要亂加
{{ value|cut:" " }}
{{ value|safe }}
{{ some_list|slice:":2" }}
{{ value|truncatechars:5 }}
官方文檔https://docs.djangoproject.com/en/2.0/ref/templates/builtins/
緩存