Django- итерация a через цикл for
В моем шаблоне django есть следующий цикл for, отображающий элементы в списке 'question'. Я хочу вывести значение согласно позиции индекса в списке. Однако когда я пытаюсь вывести его, в браузере ничего не отображается. Я использовал функцию range в моем контексте и инициализировал ее значением 2 в ключевом имени 'n'.
Это мой контекст
context = {'range' : range(2),
'question': input_question,
'most_sim_Q': result[6],
'question_scores': question_scores}
return render(request, 'predict/result.html', context)
это шаблон
{% extends 'predict/base.html'%}
{% block content %}
{% for text in range %}
<!--parsing the input question-->
<h2>Input Question: </h2><br>
{{question.text}}
<!--Parsing the most similar question-->
<h2>most similar question's are: </h2><br>
{{most_sim_Q.n.most_sim_Q}}
<!--parsing the top 10 most smilialr question-->
<h2> Top 10 most similar questions found are : </h2><br>
{%for ques_key, values in question_scores.items%}
{% for que, score in question_score.i.items %}
<h3> {{ que }} ==> {{score}} </h3>
{% endfor %}
{% endfor %}
<h3>--------------------------------------------------</h3>
{% endfor %}
{% endblock content %}
Я печатаю question.text, где question - список, содержащий два значения, но {{question.text}}. Вот мой вывод
Input Question:
most similar question's are:
Top 10 most similar questions found are :
--------------------------------------------------
Input Question:
most similar question's are:
Top 10 most similar questions found are :
--------------------------------------------------
не работает, потому что синтаксис Jinja2 отличается от того, что вы пишете. Вместо {{question.text}} синтаксис {{question[text]}}. Попробуйте изменить свой код на такой