Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1109635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:16:05+00:00 2026-05-17T02:16:05+00:00

I want to refresh a div tag in Django that contains temperature data. The

  • 0

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:

function refresh() {
$.ajax({
  url: '{% url monitor-test %}',
  success: function(data) {
  $('#test').html(data);
  }
});
};
$(function(){
    refresh();
    var int = setInterval("refresh()", 10000);
});

And this is my urls.py:

urlpatterns += patterns('toolbox.monitor.views',
    url(r'^monitor-test/$', 'temperature', name="monitor-test"),
    url(r'^monitor/$', 'test', name="monitor"),
)

views.py:

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})

temp.html has an include tag:

<table id="test"><tbody>
<tr>
{% include "testing.html" %}
</tr>
</tbody></table>

testing.html just contains a for tag to iterate through the dictionary:

{% for label, value in temperature.items %}
      <td >{{ label }}</td>
      <td>{{ value }}</td>
{% endfor %}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:16:06+00:00Added an answer on May 17, 2026 at 2:16 am

    The way I normally get around the 3-4 "concurrent" requests for such situations is to put the setTimeout() call inside the function I want to run repeatedly.

    function refresh() {
        $.ajax({
            url: '{% url monitor-test %}',
            success: function(data) {
                $('#test').html(data);
            }
        });
        setTimeout(refresh, 10000);
    }
    
    $(function(){
        refresh();
    });
    

    That makes it so every time the refresh function is called, it will automatically set itself to be called again in 10 seconds. Another idea (if you still have problems) is to move the setTimeout into the success function in the AJAX call:

    function refresh() {
        $.ajax({
            url: '{% url monitor-test %}',
            success: function(data) {
                $('#test').html(data);
                setTimeout(refresh, 10000);
            }
            
        });
    }
    
    $(function(){
        refresh();
    });
    

    That option might be a little bit sketchy if, for whatever reason, the AJAX call does not succeed. But you can always get around that with other handlers, I suppose…

    One suggestion I have (not particularly related to your question) is putting the whole <table> thing in the template that you render and return your temperature view. So, in your main template:

    <div id="test">
    {% include 'testing.html' %}
    </div>
    

    and in testing.html:

    <table><tr>
    {% for label, value in temperature.items %}
        <td>{{ label }}</td>
        <td>{{ value }}</td>
    {% endfor %}
    </tr></table>
    

    Something about inserting part of a table the way you currently have it makes me want to cry 🙂 Sending a few more bytes over the wire in AJAX calls shouldn’t hurt anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that the function is to refresh div tag. Div tag
I have couple of formulas and data coming from database. I want to refresh
I have a page which reloads a DIV with AJAX every 5 seconds. I
i'm using this piece of code to refresh my div every X seconds: <script>
I want to refresh my table every 5 seconds.. Now I'm using this code
I have a div tag on my site that uses a background image. When
I want to refresh a table using a SSIS package every time the user
I've got two input boxes in a div, I want to hide that div
I want to use $.post function of jquery to do a div refresh, only
So, here's the deal. I have an html table that I want to populate.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.