Skip to content
Advertisement

How to display current date and time on Django website?

I know how to print out current date and time in the console, but I am trying to add the date/time as a feature on my daily task Python website using Django and Bootstrap4.

I have tried adding it as a function in my views.py file and then inserting the function in the html file of the page i want it to be on, but everything I have tried has not worked.

Here is the function I created at first in views.py:

JavaScript

Then I began playing around and tried this:

JavaScript

And this is what I tried adding to the html file:

JavaScript

Update – Trying this and still does not show anything:

JavaScript

Advertisement

Answer

If you just want to display only in the template then you can do this

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement