-Custom functions
Simple_tag
A. Create templatetags directory under App
B. Any xxoo.py file
C. Creating a Template object register
D.
__author__ = ' Administrator '
From Django Import Template
From django.utils.safestring import Mark_safe
Register = template. Library ()
@register. Simple_tag
def func (A1,a2,a3 ...)
Return "ASDFASD"
E. Register app in Settings
F. Top {% load Xxoo%}
G. {% function name arg1 arg2%}
Disadvantages:
cannot be used as an if condition
Advantages:
Parameter any
Filter
A. Create templatetags directory under App
B. Any xxoo.py file
C. Creating a Template object register
D.
@register. Filter
def func (A1,A2)
Return "ASDFASD"
E. Register app in Settings
F. Top {% load Xxoo%}
G. {{parameter 1| function name: "Parameter two, parameter three"}} {{parameter 1| function name: number}}
Disadvantages:
Up to two parameters, cannot add a space
Advantages:
Can be used as an if condition
Custom Functions for Django templates