The main idea in the following: I have a list and a value, which I get from template. So, I need to take a first element of that list –
list['value']
In template I have:
{% load get_number %}
{{ list, value |get_number }}
in get_number.py:
#!/usr/bin/python
from django import template
register = template.Library()
@register.filter(name='get_number')
def get_number(arr, value):
return arr[int(value)]
But it doesnt work. I search in Google, it said, that Django doesnt support a few elements in the filter ( {{ list, value |get_number }}). Its very strange to me, because in php I can do $list[‘value’] without any filtres, etc. How to fix that?
do like this
FYI: you can use a dot notation to index the list in template