在Django模板中重新定义默认过滤行为 [英] redefine default filtering behavior in Django templates

查看:235
本文介绍了在Django模板中重新定义默认过滤行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,许多DecimalFields被渲染在300多个模板中。我希望这些十进制字段被归一化。我不在乎排除或任何东西:

  decimal.Decimal(10.0000)。normalize()
我没有找到一种更改默认渲染系统的方法。我知道有一个人性化和一个floatformat过滤器我可以在我的模板中使用。但是我需要一个解决方案,并不意味着编辑所有这些文件,即使可以写一个shell脚本。



谢谢

解决方案

我终于想出了这个答案问题并发布在我的博客中:
http://tothinkornottothink.com/post/2156476872 / django-positivenormalizeddecimalfield



我希望有人觉得有用


I have a project with many DecimalFields that are rendered in more than 300 templates. I would like that these decimal fields are rendered normalized. I don't care about precission or anything:

decimal.Decimal("10.0000").normalize()

I haven't found a way to change default rendering system. I know there is a humanize and a floatformat filter I could use in my templates. But I need a solution that doesn't mean editing all those files, even if a shell script could be written.

Thanks

解决方案

I finally came up with the answer to this question and posted it in my blog: http://tothinkornottothink.com/post/2156476872/django-positivenormalizeddecimalfield

I hope somebody finds it useful

这篇关于在Django模板中重新定义默认过滤行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆