1

I am very new to web design and I need help with a problem I have at the moment. I have written a web page with the help of Django that pulls values out of a MySQL database and places them on webpage using an embedded for loop. The values in the database are constantly updated and to get the new values displayed at the moment I am simply refreshing the page. This method seems very clunky and I was wondering if there was easy way to have them update without a refresh?

!DOCTYPE html>

<html lang="en">

<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0.5">
<link rel="stylesheet" href="css/style.css">
<link href="images/favicon.ico" rel="shortcut icon">
<title>Health monitor</title>
</head>

<body>

<div class="container">
<h1>Health Monitor</h1>
<h2>Temperature Data</h2>
    {% for heat in temp %}
<h3>Current temperature {{ heat.hot }} </h3>
<p>You might want to call a nurse</p>
    {% endfor %}

Captain Obvlious
  • 18,863
  • 5
  • 39
  • 72
Sam Little
  • 21
  • 4

1 Answers1

1

There are a couple ways, perhaps the simplest and most accessible would be to use ajax polling to request updates on an interval.

This would be done in JavaScript. Every x seconds you would make a request to your django app to see if there are any changes.

BenMorel
  • 31,815
  • 47
  • 169
  • 296
dm03514
  • 52,703
  • 18
  • 104
  • 141