Ama*_*ngh 3 python django django-templates django-template-filters
我正在寻找一个模板标签,以将 522 之类的值仅转换为 522。查看我遇到的文档
django.contrib.humanize
它有一个内置标签 intword 但它只适用于数字大于一百万的数字。
作为替代解决方案,我使用Python 脚本中的函数创建了一个标签, 用于将数字转换为单词以打印支票
请建议是否有更好的解决方案。
查看这个库:num2words
直接来自文档:
>>> from num2words import num2words
>>> num2words(42)
forty-two
>>> num2words(42, ordinal=True)
forty-second
>>> num2words(42, lang='fr')
quarante-deux
Run Code Online (Sandbox Code Playgroud)