1. 在app中创建文件夹templatetags
2. 创建文件xx.py
from django import template
register = template.Library()
@register.filter
def my_upper(value,v1):
return (value+v1).upper()
@register.simple_tag
def my_smaller(value,v1,v2,v3):
return (value+v1+v2+v3).lower()
3. 加载标签到模板文件
{% load xx %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Classes</title>
</head>
<body>
<h1>simple filter</h1>
{{ name | my_upper:'666' }}
<h1>simple tag</h1>
{% my_smaller name 'hi' 'ho' 'jk' %}
</body>
</html>