Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django在模板中使用if标记将一个变量与一个数字进行比较时总是给出false_Python_Django_Twitter Bootstrap 3 - Fatal编程技术网

Python Django在模板中使用if标记将一个变量与一个数字进行比较时总是给出false

Python Django在模板中使用if标记将一个变量与一个数字进行比较时总是给出false,python,django,twitter-bootstrap-3,Python,Django,Twitter Bootstrap 3,我首先使用widthratio标记来计算比率百分比,并将其关联到名为ratio的变量 然后,当我尝试将它与if和elif标记中的整数进行比较时,if和elif标记似乎都是假的,我总是转到最后的else标记,得到错误的结果。 下面是我的源代码: <div class="container-fluid"> <p><span class="icon-group"></span> Player registratered: {{

我首先使用widthratio标记来计算比率百分比,并将其关联到名为ratio的变量 然后,当我尝试将它与ifelif标记中的整数进行比较时,ifelif标记似乎都是假的,我总是转到最后的else标记,得到错误的结果。 下面是我的源代码:

     <div class="container-fluid">
        <p><span class="icon-group"></span> Player registratered:  {{event.Players_registratered}}/{{event.Max_players}}</p>
        {% widthratio event.Players_registratered event.Max_players 100 as Ratio %}
        {{Ratio}}
        <div class="progress progress-striped active text-center">
          {% if Ratio < 30 %}
            <div class="progress-bar progress-bar-info" role="progressbar"
                        aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:{{Ratio}}%">
            </div>
          {% elif Ratio < 70 %}
            <div class="progress-bar progress-bar-success" role="progressbar"
                        aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:{{Ratio}}%">
            </div>
          {% elif Ratio < 90 %}
            <div class="progress-bar progress-bar-warning" role="progressbar"
                        aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:{{Ratio}}%">
            </div>
          {% else %}
            <div class="progress-bar progress-bar-danger" role="progressbar"
                        aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:{{Ratio}}%">
            </div>
          {% endif %}
        </div>
      </div>

玩家注册:{{event.Players\u registered}}/{{event.Max\u Players}

{%widthratio event.Players\u registered event.Max\u Players 100 as Ratio%} {{Ratio}} {如果比率<30%,则为%1} {%elif比率<70%} {%elif比率<90%} {%else%} {%endif%}
和输出剪报:


我希望有人能回答。非常感谢。

截图看起来不错,到底有什么地方不正确?如果每次转到最后一个
else
条件,所有条都将是100%。比率是一个数字吗?如果Ratio是String,if-elif总是错误的。我在Widthratio标记中使用的两个变量在models.py中是整数,当我将结果分配给Ratio时,我不确定它是否转换为String。顺便说一下,当我使用{Ratio | add:“5”}时,它会给出正确的计算答案。为什么不在
with
标记的开头使用
with
?像这样:
{%with widthratio event.Players\u registered event.Max\u Players 100 as Ratio%}
谢谢枪手。我在“if”和“endif”之前使用了
with
endwith
标记,但问题仍然存在。可变比率似乎一直存在,没有使用“with”标记。屏幕截图看起来不错,到底有什么不正确的地方?如果每次转到最后一个
else
条件,所有条都将是100%。比率是一个数字吗?如果Ratio是String,if-elif总是错误的。我在Widthratio标记中使用的两个变量在models.py中是整数,当我将结果分配给Ratio时,我不确定它是否转换为String。顺便说一下,当我使用{Ratio | add:“5”}时,它会给出正确的计算答案。为什么不在
with
标记的开头使用
with
?像这样:
{%with widthratio event.Players\u registered event.Max\u Players 100 as Ratio%}
谢谢枪手。我在“if”和“endif”之前使用了
with
endwith
标记,但问题仍然存在。可变比率似乎一直存在,没有使用“with”标记。