Improving the return of a specific result

Asked

Viewed 64 times

2

I think I’m letting go of the basics!

I have a result that returns me only one element in the dictionary:

[{'quant': 236, 'district': 'Centro'}]

My context is:

context['Districts'] = d

How do I make in the template I write something like

{{ Districts.district }} - {{ Districts.quant }}

instead of

{% for i in vehicleDistrict %}
    {{ i.dealership__district }} - {{ i.quant }}
{% endfor %}

Since the interaction is only one item?

1 answer

2


In reality it returns only one element in the list, for this just take the first element (unique in this case) and pass to the template.

view:

d = [{'quant': 236, 'district': 'Centro'}][0]

template:

{{ d.quant }} - {{ d.district }}

You can still use this feature directly in the template but I don’t find it a good practice:

{{ District.0.quant }}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.