如何禁用充当链接django的按钮

时间:2017-08-31 02:31:47

标签: python html django button hyperlink

单击“批准”按钮时,禁用“拒绝”按钮的最佳方法是什么?我有{{some}}存储批准或拒绝值的值。

let routes = [{path: ..., component : ...}, ...];
RouterModule.forRoot(routes, {
                       enableTracing: /localhost/.test(document.location.host)
                     });

html文件

<a href="{% url 'hrfinance:edit' id=item.id status='a' %}"><button>Approve</button></a> 
<a href="{% url 'hrfinance:edit' id=item.id status='d' %}"><button>Deny</button></a> 

{{some}}从这里获取

views.py

{% if some %}
    <table  id="example" class="display" cellspacing="0" width="100%" border="1.5px">
     <tr align="center">
     <th> Student ID </th>
     <th> Student Name </th>
     <th> Start Date </th>
     <th> End Date </th>
     <th> Action </th>
     <th> Status </th>
     </tr>
     {% for item in query_results %}
         <tr align="center">
             <td> {{item.studentID}} </td>
             <td> {{item.studentName}} </td>
             <td> {{item.startDate|date:'d-m-Y'}} </td>
             <td> {{item.endDate|date:'d-m-Y'}} </td>
             <td><a href="{% url 'hrfinance:edit' id=item.id status='a' %}"><button>Approve</button></a> <a href="{% url 'hrfinance:edit' id=item.id status='d' %}"><button {% if some == 'approve' %} disabled{% endif %}>Deny</button></a></td>
             <td> 
                 {% if item.status %}
                     {{item.status}}
                 {% else %}
                      Pending
                 {% endif %}       
             </td>
       </tr>
       {% endfor %}
       </table>
{% else %}

2 个答案:

答案 0 :(得分:1)

使用if tag

<button{% if some == 'deny' %} disabled{% endif %}>Approve</button>

答案 1 :(得分:0)

我不确定你在问什么,但你可以做一个if语句,如

{% if some == 'approve' %}
    <a href="{% url 'hrfinance:edit' id=item.id status='d' %}"><button>Deny</button></a>
{% else %}
    <a href="{% url 'hrfinance:edit' id=item.id status='a'%}"><button>Approve</button></a>
{% endif %}

或:

{% if some == 'approve' %}
    <button>Deny</button>
{% else %}

告诉我这是否有效或我误解了