i have a html file that get my product model from database and show price of products.
i have a view:
def product(request):
all_products = Product.objects.all()
return render(request, 'index.html', {'products':all_products})
and in html file i write:
{% for item in products %}
{{ item.price }}
{% endfor %}
i want for price for example: 1000000 $
output in html file show like this: 1,000,000 $
is there anyway to do this? i’m not familiar with java script… so please help!
2
Answers
You can use intcomma template filter to achieve that. Activate the filter by adding
django.contrib.humanize
to yourINSTALLED_APPS
setting. Then use{% load humanize %}
in your html template.You then add it to your variable like:
You can also do
USE_THOUSAND_SEPARATOR = True
insettings.py
. Reference: https://stackoverflow.com/a/73407763/18891495