Jinja pattern doesnt work inside a for loop

34 views
Skip to first unread message

Chinmay Dali

unread,
Jan 25, 2020, 5:11:33 AM1/25/20
to Django users
I am trying to loop over a product list{more so a queryset} in django using for loop, by adding the range of products The following code works when printed out in cmd prompt
I am doing something like this
'''
for card in allproduct[nextRangePage:limit]:
'''
 in django template using this
'''
{% for card in allproduct[{%'nextRangePage'%}:{%'limit'%}] %}
'''
it gives the following the error:
```
django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '[{%'nextRangePage'' from 'allproduct[{%'nextRangePage''
```

Jason

unread,
Jan 25, 2020, 7:56:48 AM1/25/20
to Django users
While you can use Jinja templates in django, that requires additional configuration to ensure the proper template renderer is used.  Otherwise, by default, django uses its own template renderer.

You don't say whether you've taken the necessary steps to have your django project use Jinja, and from the output you posted, it seems unlikely.

So, the documentation on templates is pretty thorough in the steps you need to take, or use django template syntax.

Jani Eric

unread,
Jan 25, 2020, 7:59:08 AM1/25/20
to Django users
thanks bro

Aditya Khatwa

unread,
Jan 25, 2020, 5:22:33 PM1/25/20
to django...@googlegroups.com
Use custom templates tag instead doing it directly... make a function stating your {% query_set %} and then use it inside the template. 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a9b2cafa-d9eb-4ec7-a3f7-24edd1f42ee7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages