app:auto
在auto 下面新建templatetages __init__.py为空
[root@56ee92471bf3 apps]# tree auto/ auto/ ├── admin.py ├── views.py ├── __init__.py ├── templatetags │ ├── __init__.py │ ├── myfilter.py
[root@56ee92471bf3 apps]# cat auto/templatetags/myfilter.py
#!/usr/bin/python
# -*- coding : utf-8 -*-
from django import template
register = template.Library()
def too(value,arg=None):
return value + value
register.filter('too', too)
html代码:
{% load myfilter %}
{% for line in allresult %}
{{line|too}} <br/>
{% endfor %}注意:
需要重启,才能加载刚才的类
参考:https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters
