我目前正从我的视图中获取一个对象,并以表格的形式将其显示在模板中。 目前,我很震惊我们需要刷新表/ div的部分,而不刷新页面。
在我的views.py中
def foo(request): testruns...... render_to_response('pages/bar.html', locals(), context_instance=RequestContext(request))我的bar.html(模板)
<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>应该有两种方法可行:
使用dajaxice使用[Jquery]
$.ajax({ url: '{% url myview %}', success: function(data) { $('#the-div-that-should-be-refreshed').html(data); } });我想知道哪种方法更适合我的情况。 使用方法2,表格会自动刷新,我们如何设置刷新时间?
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.
In my views.py
def foo(request): testruns...... render_to_response('pages/bar.html', locals(), context_instance=RequestContext(request))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>There are two approaches which are supposed to work:
Using dajaxiceUsing [Jquery]
$.ajax({ url: '{% url myview %}', success: function(data) { $('#the-div-that-should-be-refreshed').html(data); } });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):
通过网络传输的数据要大得多
如果您在表中使用基于javascript的组件(可能是基于dojo的按钮等),他们可能会遇到一些问题。 我在dojo中遇到了一个微笑的问题,我在make dojo中找到了解压缩应用的html的解决方案。 但每次生活都不容易,所以第一种方法更好。
Both acceptable but disadvantages of the second approach(pulling table from django as html ):
Carried data over network is much bigger
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.
更多推荐
发布评论