Forums

current date in web app is not updated

I deployed my application yesterday 21/1/2017. My app has a lot of functions depending on current date (i.e. Calendar, filterings etc). <p>Today when I logged in, the date is still 21/1/2017, which means it is not updated.</p> <p>I am using python's dateutil (i.e. today = datetime.now() ) </p>

Why is this happening?

where are you setting today = datetime.now()? is it within a function? or just at the module level?

I am using django so this is done at the top of the views.py file

I just notice that this is fixed only if I reload the app every day. Is there a way to do this automatically?

that's because you aren't setting/recomputing today inside of a function. if it is module level then it only gets run initially/never again until you reload.

Not sure if you got this resolved, but I had what appeared to be a similar issue.

Displaying the current date from python was not working, then suddenly it worked. Reason is that I am in Australia so pythonanywhere's current date is different to my local time.

The only way to resolve this was to use javascript.

In the base.html template file (at the end) put a function to setup where you want your date

<script>
var elem = document.getElementById("timeNow")
var now = new Date();
var options = { format: 'DMY', weekday: 'long', year: 'numeric', month: 'long', day: '2-digit' };
elem.innerHTML = now.toLocaleString('en-au', options);
</script>

Then on the page you want it displayed, add that element "timeNow"

e.g. on my calendar page

   <span id="timeNow"></span>

This works fine, but if there is a cleaner (non javascript) way that anyone has used, I'd love to know about.

Cheers, Duncan

thanks for the input! it's not what the other user had a problem with, but that's quite useful information for others browsing this page as well!

(the other user had a problem where they generated the date once, and used it forever, and never generated the date again- so the date was frozen in time)