1.新建templates python包
2.新建index_tags.py文件(文件名自定义)
3.自定义简单标签
@register.simple_tag(name='ttag') def addstr_tag(strs): return 'hello %s'%strs
{% load index_tags %} {% addstr_tag 'abc' %}
自定义标签重命名
@register.simple_tag(name='ttag')
添加path
path('test_simpletag/',views.test_simpletag)
访问/test_simpletag
4. 自定义引用标签
@register.inclusion_tag('inclusion.html',takes_context=True) #定义函数渲染模板 def add_we