Django template - dynamic variable name

后端 未结 2 1441
孤独总比滥情好
孤独总比滥情好 2020-12-20 20:54

Good Afternoon,

How can I use a variable variable name in Django templates?

I have a custom auth system using context, has_perm che

2条回答
  •  無奈伤痛
    2020-12-20 21:17

    You can try like this,

    {{ dict|key:key_name }}
    

    Filter:

    def key(d, key_name):
        return d[key_name]
    key = register.filter('key', key)
    

    More information, django ticket

提交回复
热议问题