The task is to update the values of specific HTML tags by timer, without reloading the entire page, the code below requests a Django representation in a JS loop.
urls.py
from django.conf.urls import include, url from opc_app import views from opc_app.views import * urlpatterns = [ url(r'Main_DateTime/', DateTime_main_func), url(r'Template_DateTime/', Actual_DateTime_template_func, name="Template"), ] views.py
from __future__ import unicode_literals from django.shortcuts import render import datetime from datetime import time from django.http import HttpResponse def Actual_DateTime_template_func (request): now_date = datetime.datetime.now() out_values = { "DateTime": now_date, "Time": now_date.time(), } return render (request, "Actual_DateTime_template.html", context = out_values) def DateTime_main_func (request): return render (request, "Main_DateTime.html") Actual_DateTime_template.html
{{ DateTime }} <br> {{ Time }} Main_DateTime.html
<body> <p class="Rand_Time"></p> <p class="Rand_Time"></p> <p class="Rand_Time"></p> <p class="Rand_Time"></p> <script> $(document).ready(function(){ Call_Update_func(); function Call_Update_func() { $('.Rand_Time').load("{% url 'Template' %}"); setTimeout(Call_Update_func, 1000); } }); </script> </body> The problem is that you need to display different Django variables in each tag, if you select id, you get to write a function for each variable, advise how you can organize an optimal data sample, thank you!