1

I have

{% for competency in domain.competency_set.all %}
<td> {{competency.id}} {{scoredict.8}}  {% with cid=competency.id %} {{ scoredict.cid }} {% endwith %} </td> 

so scoredict.8 displays a value but when competency.id is 8, scoredict.cid comes up empty. What am I doing wrong? What's the workaround?

I can see why scoredict.competency.id doesn't work, but I don't see how to change the order of evaluation. If I could force order of evaluation with parentheses I'd want something like scoredict.(competency.id)

mt_
  • 129
  • 1
  • 9
  • 1
    Basically, django templates deliberately don't do that (unless the world has changed since I last looked at it). Typically you'd try to find a design that doesn't require it, probably by preprocessing in your view, or write a custom tag or filter. – Peter DeGlopper May 10 '18 at 20:38
  • Thanks. To be specific added from django import template register = template.Library() @register.filter def get_item(dictionary, key): ... return dictionary.get(key,"") to /templatetags/_extras and put `{% load _extras %}` in the template. Then `{{ scoredict|get_item:competency.id }}` did the trick. Thanks! – mt_ May 10 '18 at 21:19

0 Answers0