If 语句看起来不会扩展到其他模板
我的 django 模板上的 if 语句之一有问题。
目前我的 base.html 上有这个,它扩展到其他模板:
base.html
{% if user.is_superuser %}
<h2>Admin Menu</h2>
<table>
<tr>
{% if approved %}
<td><a href="{% url rates-disable_rates %}" class="mbbutton ui-state-active ui-corner-all">Disable Rates</a></td>
{% else %}
<td><a href="{% url rates-approve_rates %}" class="mbbutton ui-state-active ui-corner-all">Approve Rates</a></td>
{% endif %}
</tr>
{% if life %}
{% include 'rates/admin_life_rates_menu.html' %}
{% else %}
{% include 'rates/admin_broker_rates_menu.html' %}
{% endif %}
</table>
{% endif %}
现在我有某些类别的费率,例如 X 费率、Y 费率等。每个都有自己的按钮。
示例:
<form method="get" action=".">
<input type="hidden" name="product_code" value="{{ product_code }}"/>
<input type="hidden" name="paymode_code" value="{{ paymode_code }}"/>
<input type="hidden" name="compoundmode_code" value="{{ compoundmode_code }}"/>
{% if life %}<input type="hidden" name="life" value="{{ life }}"/>{% endif %}
{% if tfsa %}<input type="hidden" name="tfsa" value="{{ tfsa }}"/>{% endif %}
</form>
如果费率获得批准,则链接将显示为“禁用费率”(自然相反),反之亦然,即费率尚未获得批准。
所以我的问题是,当我单击查看其他费率时,if 语句似乎不起作用。
如果费率已获得批准,则链接会显示批准,即使这是不正确的。关于为什么这个 if 语句不起作用的任何想法?
非常感谢,如果我需要显示更多代码段,请询问,我很乐意将它们贴上来。
I have a problem with one of my if statements on my django template.
Currently I have this on my base.html which extends to other templates:
base.html
{% if user.is_superuser %}
<h2>Admin Menu</h2>
<table>
<tr>
{% if approved %}
<td><a href="{% url rates-disable_rates %}" class="mbbutton ui-state-active ui-corner-all">Disable Rates</a></td>
{% else %}
<td><a href="{% url rates-approve_rates %}" class="mbbutton ui-state-active ui-corner-all">Approve Rates</a></td>
{% endif %}
</tr>
{% if life %}
{% include 'rates/admin_life_rates_menu.html' %}
{% else %}
{% include 'rates/admin_broker_rates_menu.html' %}
{% endif %}
</table>
{% endif %}
Now I have rates for certain categories, for example X rates, Y rates, etc. Each with their own button.
Example:
<form method="get" action=".">
<input type="hidden" name="product_code" value="{{ product_code }}"/>
<input type="hidden" name="paymode_code" value="{{ paymode_code }}"/>
<input type="hidden" name="compoundmode_code" value="{{ compoundmode_code }}"/>
{% if life %}<input type="hidden" name="life" value="{{ life }}"/>{% endif %}
{% if tfsa %}<input type="hidden" name="tfsa" value="{{ tfsa }}"/>{% endif %}
</form>
If rates are approved the link is displayed as 'disable rates' (the reverse, naturally) and vice versa is the rates havent been approved.
So my issue is that the if statement doesn't seem to work when I click to view the other rates.
If the rates are already approved, the link shows approve, even though that is incorrect. Any ideas as to why this if statement wouldn't be working?
Thanks so much and if there is any more code segments I need to display just ask, and I will gladly put them up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎没有在视图中提供
approved
变量,因此它的计算结果为''
,这是错误的。It seems you're not providing the
approved
variable in your view, so it evaluates to''
, which is false.