首页 > 解决方案 > 无法解析剩余部分:来自“forloop .counter”的“.counter”

问题描述

< h1 > {{ question.question_text }} </ h1 >

{% if error_message %} < p >< strong > {{ error_message }} </ strong ></ p > {% endif %}

<form action = " {% url 'polls:vote' question.id %} " method = "post" >
{% csrf_token %}
{% for choice in question.choice_set.all %}
    <% input type = "radio" name = "choice" id = "choice {{ forloop .counter }} " value = " {{ choice.id }} "% >
    < label for = "choice {{ forloop .counter }} " > {{ choice.choice_text }} </ label >< br >
{% endfor %}
< input type = "submit" value = "Vote" >
</form >

运行命令时出现此错误:python manage.pyrunserver

django.template.exceptions.TemplateSyntaxError:无法解析剩余部分:来自“forloop .counter”的“.counter”

我该如何解决这个错误?

标签: pythondjango

解决方案


推荐阅读