Note that there are some explanatory texts on larger screens.

plurals
  1. PORefresh div using JQuery in Django while using the template system
    text
    copied!<p>I want to refresh a div tag in Django that contains temperature data. The data is fetched every 20 seconds. So far I have achieved this using these functions:</p> <pre><code>function refresh() { $.ajax({ url: '{% url monitor-test %}', success: function(data) { $('#test').html(data); } }); }; $(function(){ refresh(); var int = setInterval("refresh()", 10000); }); </code></pre> <p>And this is my urls.py:</p> <pre><code>urlpatterns += patterns('toolbox.monitor.views', url(r'^monitor-test/$', 'temperature', name="monitor-test"), url(r'^monitor/$', 'test', name="monitor"), ) </code></pre> <p>views.py:</p> <pre><code>def temperature(request): temperature_dict = {} for filter_device in TemperatureDevices.objects.all(): get_objects = TemperatureData.objects.filter(Device=filter_device) current_object = get_objects.latest('Date') current_data = current_object.Data temperature_dict[filter_device] = current_data return render_to_response('temp.html', {'temperature': temperature_dict}) </code></pre> <p>temp.html has an include tag:</p> <pre><code>&lt;table id="test"&gt;&lt;tbody&gt; &lt;tr&gt; {% include "testing.html" %} &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; </code></pre> <p>testing.html just contains a for tag to iterate through the dictionary:</p> <pre><code>{% for label, value in temperature.items %} &lt;td &gt;{{ label }}&lt;/td&gt; &lt;td&gt;{{ value }}&lt;/td&gt; {% endfor %} </code></pre> <p>The div is refreshed every 10 seconds and allows me to use the template system without patching it with js. However, I get repeated calls to '/monitor-test', 3-4 at the same time after a couple of minutes. Also, I was wondering if there is a better way to do this while being able to use the template system in Django. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload