HTML页面未显示值

时间:2017-10-26 12:09:54

标签: jquery python html django

我有一个Python Web应用程序,它将参数从数据库发送到HTML页面 当页面加载时我看不到结果。

我已在检查模式下检查网络选项卡,我可以看到值已到达页面。

页面中未显示的参数是: chaccount_id,bank_name,Company,seq_id

这是我的代码:

<form id="accounts_form" method="post" enctype="multipart/form-data">
    {% csrf_token %}
    {% load staticfiles %}
Account Number:<input  list="accountslist" id="accounts_id" name="accountsname"  value="{{ Account_id }}" >
<button id="getacc_id" type="submit" name="getacc" value="commit">Get Account Details</button>
 <img id="GETACC_loading" src="{% static "app/images/small_loading.gif" %}" hidden>
    <br />   <br />
  <br /><br />

   <datalist id="accountslist">
     <select id="accounslist" size="5">
         {% for account in  accounts  %}
         <option value="{{ account.0 }}"></option>
         {% endfor %}
         </select>
     </datalist>

   </form>


<table id="theTable" hidden>
<thead>
<tr>
      <td>Account id</td>
      <td>Bank Name</td>
      <td>Company Name</td>
      <td> Counter</td>
</tr>
</thead>
<tbody>
<tr>
  <td>{{ chaccount_id }}</td>
  <td>{{ bank_name }}</td>
  <td>{{ Company }}</td>
  <td>{{ seq_id }}</td>
</tr>

</tbody>
</table>
 {% endblock %}
{% block scripts %}
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<script>
    $(function () {
        $('#getacc_id').click(function(evt){
               acctoshow=document.getElementById('accounts_id').value;
                evt.preventDefault();
            $('#GETACC_loading').show();
            $.ajax({
                type: "POST",
                url: 'Accountinfo',
                data: {
                    'acctoshow' : acctoshow,
                    'csrfmiddlewaretoken': '{{ csrf_token }}'
                },
                success: function (data, textStatus, jqXHR) {
                    $('#theTable').DataTable(
           {

               stateSave: true,
               "sDom": 'C<"clear">rfrtip',
               "scrollCollapse": true,
               "paging": true,
               responsive: true
        });    
    $('#theTable').show();             
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $('#rb_loading').hide();
                    alert("could not find accoutn detials, please try again!");
                }
            })
        });

     $('#updaterec_id').click(function () {
            bankname=document.getElementById('newbanks_id').value;
            companyname=document.getElementById('newcompany_id').value;
            counterid=document.getElementById('ncounterid').value;
            accid=document.getElementById('retriveacc_id').value;
            $('#GETACC_loading').show();
            $.ajax({
                type: "POST",
                url: 'Accountinfo',
                data: {
                    'bank' : bankname,
                    'company' : companyname,
                    'seq' : counterid,
                    'account' : accid,
                    'csrfmiddlewaretoken': '{{ csrf_token }}'
                },
                success: function (data, textStatus, jqXHR) {
                      $('#GETACC_loading').hide();      
                     alert("Account Details were updated!");
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $('#GETACC_loading').hide();
                    alert("could not update account detials, please try again!");
                }
            })
        });

      });
    </script>
    {% endblock %}

谢谢,

Nir ​​

1 个答案:

答案 0 :(得分:0)

您应该使用渲染函数在上下文中传递数据,例如:https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/#render