Django自定义过滤器

1.编写过滤器函数myfilter.py

# -*- coding: utf-8 -*-
from django import template
register = template.Library()

# 定义一个将日期中的月份转换为大写的过滤器,如8转换为八
@register.filter
def month_to_upper(key):
        return ['', '', '', '', '', '', '', '', '', '', '十一', '十二'][key.month-1]

2.页面

{% load myfilter %}
<div class="month">{{ bean.create_date | month_to_upper }}</div>

 

posted @ 2017-05-14 20:19  413Xiaol  阅读(132)  评论(0)    收藏  举报