1, django 中app 下目錄料皇,創(chuàng)建和 templates 同目錄文件 templatetags python文件夾介返,再再templatetags下創(chuàng)建get_mod.py
-----------get_mode.py--start------------------
# -*- coding:utf-8 -*-
fromdjangoimporttemplate
register = template.Library()
# 自定義過濾器:獲取絕對值,
@register.filter
defget_mod(arg1, arg2):
returnarg1 %int(arg2)
--------------end-----------------
2,在html中引用
-----------------------------------------------------------------------------------------------------
{%loadstatic%}
{%loadget_mod%}
主頁顯示
{%forparticipantinwx_participants%}
{%ifparticipant.id|get_mod:"2"==1%}
沒有
{%else%}
{{participant.username}}
{{participant.id}} 號
{{participant.topiao_declaration}}
閱讀全文
{%endif%}
{%endfor%}
-----------------------------------------------------------------------------------
見:http://www.bubuko.com/infodetail-2328310.html