A
A
aLap2021-11-02 14:45:21
Django
aLap, 2021-11-02 14:45:21

How to get value from dictionary in Django template based on data from queryset?

Greetings!
Apparently, I'm wildly stupid, but something doesn't go skiing.

There is a queryset, let's call it keywords, it contains the actual words (strings), there is a word_freq dictionary, it looks like this:

{
'foo': 3,
'bar': 5,
...
}


It is necessary to sort through the queryset template in the django template and display matches from the dictionary, I do it as follows:
{% for keyword in keywords %}
    {% if keyword.keyword in word_freq %}
        {{ keyword.keyword }}: {{ word_freq.keyword.keyword }}
    {% endif %}
{% endfor %}

The output should be the string foo: 3 bar: 5, etc. And I get foo: bar:. That is, the queryset successfully iterates, finds matches in the dictionary, but does not display the value from the dictionary. I suspect that the problem is in the code format word_freq.keyword.keyword

Thanks in advance!

UPD. Ultimately, I did not find a solution, combed the data in the view.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question