Django template language has so many features:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs
But I’ve been having trouble finding one. I have a dictionary in python which is sent to the HTML document.
Dictionary: hello = {'a':100, 'b':200, 'c':300, etc:etc}
In the HTML file, if I do this: {{a}} the number 100 is outputted.
Now I was wondering, if it is at all possible to use Django templates to add a character for the 100 and all other values. So like a filter that changes the output from 100 200 300 etc into 10a0 20a0 30a0 etc or even 1.00 2.00 3.00 etc. The closest I’ve found is the add built-in feature {{ value|add:"2" }} so {{ 4|add:"2" }} would give you 6.
Thanks for reading this, I’d appreciate any help!
If you really want to do this in template, here is what you can try:
But this is ugly!
I would suggest to write a simple template filter to appropriately transform the value.
For example:
in template use it as:
This would give you value as
1.00when value is100.More help on how to write, register template filters here.