django- custom template tags

    0.应用必须注册好

    1.在当前的应用中创建一个templatetags的文件夹

    2. The establishment of a python file for writing tag

    3.导入django的template类,然后实例化一个register对象

      from django import template

      register = template.Library()

    4. Custom Label

register.simple_tag @ # indicates that the function is custom label 
DEF get_bigcategory_list ():
     return BigCategory.objects.all () 

'' ' 
custom label parameter limit is not 
however correspond to the time used 
in HTML using 
{% Function name tag parameters%} 
'' '
Custom label

 

  

Guess you like

Origin www.cnblogs.com/lizhihoublog/p/12618958.html