如何在Django模板中刷新表 [英] How to refresh a table in template of Django

查看:236
本文介绍了如何在Django模板中刷新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从视图中获取一个对象,并将其以表格形式显示在模板中.目前,我对不刷新页面而需要刷新表/div的部分感到震惊.

I am currently obtaining an object from my views and displaying it in the template in form of a table. Currently I am struck at the part that we need to refresh the table/div, without refreshing the page.

在我的观点中.py

def foo(request):
  testruns......
  render_to_response('pages/bar.html', locals(), context_instance=RequestContext(request))

我的bar.html(模板)

My bar.html (template)

<div id = "roman">
    {% for trun in testruns %}

        <tr>
            <td>{{ trun.testprofile }}</td>
            <td>{{ trun.time }}</td>
            <td>{{ trun.testresult }}</td>
            <td>{{ trun.state }}</td>
        </tr>
    {% endfor %}
</div>

应该使用两种方法:

  • Using dajaxice
  • Using [Jquery]

   $.ajax({

   url: '{% url myview %}',
          success: function(data) {
          $('#the-div-that-should-be-refreshed').html(data);
          }
   });

我想知道哪种方法更适合我的情况.使用方法2,表格会自动刷新吗?我们如何设置刷新时间?

I would like to know which approach is more suitable to my case. Using Approach 2, would the table auto refresh, and how do we set the time to refresh ?

推荐答案

第二种方法都可以接受,但也有缺点(从django中将表拉为html):

Both acceptable but disadvantages of the second approach(pulling table from django as html ):

  1. 通过网络传输的数据更大

  1. Carried data over network is much bigger

如果您在表中使用了一些基于javascript的组件(也许 基于dojo的按钮等),可能会引起一些问题.我曾有一个 在dojo中出现了微笑问题,我在make dojo reparse中找到了解决方案 应用的html.但是生活不可能总是那么轻松 方法更好.

If u use something javascript based components in your table (maybe dojo based buttons etc.) they may couse some problems. I had a smilar issue in dojo and i found the solution in make dojo reparse the applied html. But life could not be easy everytime so first approach is better.

这篇关于如何在Django模板中刷新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆