I know that Django have a function that can get current time. However, it cannot continuously updates the time to the user interface (Real-time clock).
The code for getting the current time.
views.py
from datetime import datetime
from django.shortcuts import render
def clock(request):
now = datetime.now()
context = {
'current_time': now.strftime('%Y-%m-%d %H:%M:%S')
}
return render(request, 'clock.html', context)
clock.html
{% extends "base.html" %}
{% block content %}
<h1>Current Time:</h1>
<p>{{ current_time }}</p>
{% endblock %}