0

I have the following situation:

{% if accounts.count > 0 %}
    {% for account in accounts %}
      <div>Balance:<b>{{ my_dict.account.id }}</b></div>
      <div><a href="/edit/{{ account.id }}"><button>Edit</button></a></div>
    {% endfor %}
{% else %}
    <p>...</p>
{% endif %}

.

Such arrangement is ok

my_dict.account

But I'll do something like that. I have two dots

my_dict.account.id

Is there any way to do this? It would be a good idea to create a variable in template but it does not work for me

programmerJavaPL
  • 496
  • 6
  • 23

1 Answers1

0

Would be nice to see your my_dict dictionary structure: what is key (is it account id?)

It can be something like this:

my_dict[account.id]

Though if my_dict somehow doesn't have the key, you'll encounter an error. So you might wanna do this instead:

my_dict.get(account.id, 'default value')

'default value' is what will be returned in case if there's no such key in my_dict.

Tim S.
  • 162
  • 7