Найти - Пользователи
Полная версия: Передача контекста в Django
Начало » Python для новичков » Передача контекста в Django
1
dtnis19
Почему шаблонизатор не видит переменную count_votes.
Шаблон:
 {% extends "polls/wrapper.html" %}
{% block content %}
<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
    <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
{% endfor %}
</ul>
<p>Всего голосов: {{count_votes}}</p>
<a href="{% url 'polls:detail' question.id %}">Vote again?</a>
{% endblock %}
———————-
Представление:
 def results(request, question_id):
    question = get_object_or_404(Question,pk=question_id)
    count_votes
    for choice in choice_set.all():
        count_votes += choice.votes
    return render(request,'polls//results.html',{'question': question,'count_votes': str(count_votes),})
Romissevd
А так?

 def results(request, question_id):
    question = get_object_or_404(Question,pk=question_id)
    count_votes = 0
    for choice in choice_set.all():
        count_votes += choice.votes
    return render(request,'polls//results.html',{'question': question,'count_votes': str(count_votes),})
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB