2011-10-11 41 views
0

我的一個if語句在我的django模板上有問題。如果語句看起來不會擴展到其他模板

目前我有這對我的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語句不起作用的任何想法?

非常感謝,如果還有更多的代碼段需要顯示的話,我會很樂意將它們提出來。

+0

您使用的是哪個版本的Django? –

+1

我認爲你實際上在你的視圖中恰當地設置了上下文變量'approved'? –

+0

我正在使用版本1.2.1 – TheLifeOfSteve

回答

1

看來你並沒有在你的視圖中提供approved變量,所以它的計算結果爲'',這是錯誤的。