码迷,mamicode.com
首页 > 其他好文 > 详细

Django自定义过滤器

时间:2017-05-14 21:49:11      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:library   key   from   reg   rom   日期   pre   编写   imp   

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>

 

Django自定义过滤器

标签:library   key   from   reg   rom   日期   pre   编写   imp   

原文地址:http://www.cnblogs.com/413xiaol/p/6853636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!