[Django]-Django Template How to Show Money Values like 4.8p

4πŸ‘

βœ…

A template tag is just a way to use Python within a template. One possible soultion is to wrap unit_cost in another function so that it’s untouched. This is just one way i.e.

In your tags:

def multiply_cost(value):
    return value*100

register.filter('multiply_cost', multiply_cost)

Then:

({{ "Micro"|unit_cost:100|multiply_cost }}p per message)

This will give: value as x.x as required. You can expand on this, for example pass in a multiply by arg etc, but for get the idea πŸ™‚

πŸ‘€Glyn Jackson

1πŸ‘

Just multiply the value by 100:

def unit_cost(value, arg):
     # ...
     return unit_cost*100
πŸ‘€Burhan Khalid

Leave a comment