1👍
You need to register your function as a template filter. Also, this code will need to be in a module and then imported into your template as such…
# custom_filters.py
from django import template
register = template.Library()
@register.filter
def all_numbers(data):
number_list=[]
if isinstance(data, dict):
for name, address in data:
for street in data.list(): # this will raise an exception
number_list.append(street)
return number_list
# your-template.html
{% load custom_filters %}
{{ directory.addressbook.items|all_numbers }}
Source:stackexchange.com