[Answered ]-How to access object attribute via django variable?

2👍

The easiest example with filter:

# templatetags.ry
from django import template


register = template.Library()

@register.filter
def get_attr(object, name):
    return getattr(object, name, '')

Your template:

{% load templatetags %}


{% for attribute in attributes %}
    {{ entity|get_attr:attribute }}
{% end for %}

Leave a comment