Django中的模板和分頁
阿新 • • 發佈:2017-11-05
con lock turn if條件 ndb temp name ... simple
模板
在Templates中添加母版:
- 母版...html
母版(master.html)中可變化的地方加入:
{%block content%}{%endblock%}
在子版 (usermg.html) 中設置如下:
{% extends ‘master.html‘ %} {% block content%} <h1>用戶管理</h1> {%end block%}
導入小組件的模塊:
{% include ‘model.html‘ %} #同樣會載入model.html中的模板語言
自定義模板語言函數simple_tag:
{{ name|lower}} #lower函數讓name全部小寫
新建templatetags文件夾,創建函數文件xxxx.py:
from django import template from django.utils.safestring import mark_safe register = template.Library()
(1)simple_tag (不能作為if條件,參數任意)
@register.simple_tag def func_test(a): return a
在html中引入:
{% load xxxx %} {% func_test a %}
Django中的模板和分頁