skip to Main Content

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


  1. You can use intcomma template filter to achieve that. Activate the filter by adding django.contrib.humanize to your INSTALLED_APPS setting. Then use {% load humanize %} in your html template.
    You then add it to your variable like:

    {{item.price|intcomma}} 
    
    Login or Signup to reply.
  2. You can also do USE_THOUSAND_SEPARATOR = True in settings.py. Reference: https://stackoverflow.com/a/73407763/18891495

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search