1.在app中创建templatetags目录,目录名必须为templatetags

2.在目录templatetags中创建一个.py文件,例如 strFilter.py

strFilter.py  #强制转换成str

from django import template

register = template.Library()

@register.filter("strVal")   
def strVal(value):
    return str(value)

 

index.html

{% load strFilter %}

{{ssidArr.id|strVal}}

 

posted on 2017-04-28 14:38  程序小院  阅读(1223)  评论(0编辑  收藏  举报