I need to update my web page every X seconds with new information from the database. This is a relatively small application so I thought schedule would do the job.
What I have done so far:
- Getting latest value from database
- Passing on to template
- Followed schedule docs (or at least I think I did) but nothing seems to happen when I print to console just as a test.
Here is my code in views.py
:
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
from lineoee.models import Lineoee3
import threading
import time
import schedule
def job():
last_oee1 = oee_list[-1]
print(last_oee1) #test print
def index(request):
context = {}
lines = Lineoee3.objects.all().values('oee')
enter code here
oee_list = list(Lineoee3.objects.all().values_list('oee',
flat=True))
schedule.every(10).seconds.do(job)
last_oee = oee_list[-1]
var = "Current OEE is: "
context = {'lines' : lines, 'var' : var, 'last_oee' : last_oee,}
return render(request, 'lineoee/index.html',context)
The code above works well except for the schedule part
. No errors are given.
How do I print an updated version of the last oee
value every X
seconds?