How can I get first value in a dictionary in django template?

sunnyiitkgp
a = {'key1':'value1', 'key2':'value2', 'key3':'value3'...}

This dictionary is being sent to my django template. How can I get value1?

Note: I don't know key1, as it is dynamically generated.

Tomasz Jakub Rup

Use first filter with dict.values method:

{{ a.values|first }}

But remember: dict is unordered. Of course You can use OrderedDict

For OrderedDict use make_list filter :

{{ a.values|make_list|first }}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I read a dictionary in template in Django

How do I get the value of an dictionary for Django?

How do i access a dictionary value in a django template?

I can't get this foreignkey table value to be displayed in the django template

How do I access only first element in nested dictionary in Django template?

How can I get value from dictionary object?

How can I get key's value from dictionary in Swift?

How can I add value in Django 2 template

How can I show select dropdown value in django template?

Django: how can i change models variable value through template

How can I conditionally pass a value to a with variable in Django template?

If value is equal with a key in the given dictionary, how can I append to the key of the said value the value of the first key

how can I let first value to key an second value to value in the new dictionary?

How can I get {% url logout %} to work in my Django template?

How can I get index of list in django template

How can I get and display ForeignKey data in a Django template

How can I get td first child value?

How can I get first value only in each JSON object

How can I get the value of the first observable in a chain of observables relationship

How can I get the value of the first and second line in a textarea?

In a Django template, how do I print the value in a dictionary when the key is stored in a variable?

How can I get the key value pair to create a dictionary from a nested dictionary?

Why can't I fully get the value which is a list in python dictionary (Django request)?

How can I handle only the first part of my value list of a dictionary in Python?

Django how to GET value from template table?

Django How to get value of CheckboxSelectMultiple in Javascript in Template

Django template how to look up a dictionary value with a variable

How can I get the key of the object with a lowest attribute value for a Python dictionary with a string as key and a class object as value?

How can I get next value from a python dictionary after matching the key value with some string