0

I have a django view and a make a render html to return a ORM query some as

products.objects.all()
return render(request,'index.html',{"product":products})

I can make a render correctly from html page using a for cycle , the query of products this return a code and product's quantity now my problem is how i can make a cycle for print the same product twice o more depending of the product's quantity

I have sometime similar

{%for a in range({{product.quantity}})%}

but not is posible make a render correctly of template

Some idea how I should be make this cycle for into this template

solarissmoke
  • 30,039
  • 14
  • 71
  • 73
user2957682
  • 179
  • 1
  • 1
  • 8
  • Please post the actual code you are using (the code sample you have posted will not work at all) and the relevant models. As it is currently it's hard to understand what you are asking. – solarissmoke May 31 '16 at 05:00

1 Answers1

1

You're attempting to treat Django's template language as if it's an eval, and your variable {{product.quantity}} will be replaced with an integer, resulting in your statement for a in range(x) being executed.

That's incorrect.

Django's template language is not Python. It is written in Python, and it's syntax resembles Python, but is not Python. You cannot use Python within it.

Django's template language does not have a native range template tag.

See this question for an example of how to approach this.

Community
  • 1
  • 1
Jack Shedd
  • 3,501
  • 20
  • 27