You can use Ajax for this.
Here is an Example:
In your template:
Import JQuery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Then at the bottom you can do something like this
{% block script %}
<script type="text/javascript">
const interval = setInterval(function() {
// If you wish to refresh the page after calling the function
// uncomment the line below
// location.reload();
$.ajax({
type: "GET",
url: '{% url 'homepage' %}',
success: function() {
console.log('{{randomint}}')
}
});
}, 1000) // this is in milisenconds, 1000 = 1sec
</script>
{% endblock %}
This will call the url
"'homepage'
" every second,
url:
path('', views.homepage, name='homepage'),
view:
def homepage(request):
template = loader.get_template('jsondata.html')
#
# put your code here
#
randomint = randint(1, 100) # this is just for example purposes
context = {
'randomint': randomint,
}
return HttpResponse(template.render(context, request))
Note: This is just an example and will not work out of the box...
Hope this somewhat answers your question.
Extra info: Django URL in Ajax