Python 无法分析余数:';=customerreview.stars';从';val=customerreview.stars';

Python 无法分析余数:';=customerreview.stars';从';val=customerreview.stars';,python,django,Python,Django,我试图在Django模板中显示星数以供客户查看 当我尝试将值赋给变量时 {{val=customerreview.stars} 我收到此错误 无法分析“val=customerreview.stars”中的“=customerreview.stars”剩余部分。 这是mycode {% for customerreview in customerreviews %} <div class=item> <div class="rx-client-reviews rx-pa

我试图在Django模板中显示星数以供客户查看

当我尝试将值赋给变量时
{{val=customerreview.stars}

我收到此错误

无法分析“val=customerreview.stars”中的“=customerreview.stars”剩余部分。

这是mycode

{% for customerreview in customerreviews %}
<div class=item>
    <div class="rx-client-reviews rx-pading-none">
        <div class="rx-client-img rx-pading-none">
            <img src="img/main01.jpg" alt>
        </div>
        <div class=rx-pading-none>
            <h5>{{customerreview.name}}</h5>
            <h5><a href="index03.html#">{{customerreview.dasignation}}</a></h5>
            <p>{{customerreview.message}}</p>
            <div class=rx-rating>
                <ul>
                    {{val = customerreview.stars}}
                    {% for i in val%}
                    <li><span class="icon icon-Star"></span></li>
                    {% endfor %}

                    <li>
                        <p class=rating-text>{{customerreview.stars}} star rating</p>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endfor%}
{customerreviews%中customerreview的%
{{customerreview.name}
{{customerreview.message}

    {{val=customerreview.stars} {val%中的i的%1}
  • {%endfor%}
  • {{customerreview.stars}}星级

{%endfor%}

有人能帮我解决这个问题吗。tnx.

您应该将
临时标记一起使用:

{% with val=customerreview.stars %}
    ...
{% endwith %}

参考资料:

TNX。但是当我尝试循环
val
的值时。我得到的错误是,
'long'对象不可编辑
,这可能是因为
customerreview.stars
是一个很长的数字,而不是一个列表。这与使用
with
无关。关于如何在此循环,有多种可能性: