【问题标题】:Django-money. When display in template it's showing wrong format of currenncy姜戈钱。在模板中显示时显示错误的货币格式
【发布时间】:2019-10-02 10:24:47
【问题描述】:

我在 django-money 模块显示货币时遇到问题。

在模板中我使用了 2 个选项:

{{ object.balance }}{% money_localize object.balance %}

我希望在网站上看到 100.00 美元,但我得到了 100.00 美元。 与 GBP 相同 - > GB£100.00,但我想获得 £100.00。

有什么想法,为什么会这样显示?

我的模型类有字段:

balance = MoneyField(_('Balance'), max_digits=25, decimal_places=2, default=Money(0, "USD"))

【问题讨论】:

    标签: django django-models django-templates


    【解决方案1】:

    定义这个模板标签format_money.py:

    from moneyed.localization import format_money as fm
    
    @register.tag
    def format_money
        return fm(myModel.price, locale='en_US')
    

    然后在你的模板中:

    {% import format_money %}
    
    ...
    
    {% format_money object.balance %}
    

    应该可以。被盗from here

    【讨论】:

    • 被盗链接帮助:)
    猜你喜欢
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多