I have had some issues with a Django application once i used it. I personally use a Apache + mod-wsgi on the ubuntu server. Some time once i reboot the server time goes foobar, it's wrong by around -10 hrs. I designed a Django view that appears like:

def servertime():
  return HttpResponse( datetime.now() )

and once i reboot the server and appearance the url that implies that notice first looks okay. Then at some point often it provides the correct some time and sometimes not and then it provides the wrong time always. The server time is corect though.

Any clues? I have researched it without luck.

Can One call at your web addresses.py too?

Similar actions stumped me once before...

What it really switched to be was the way in which my web addresses.py known as the vista. Python went the datetime.now() once and saved that for future calls, never really calling it again. For this reason django devs needed to implement a chance to pass a function, not really a function call, to some model's default value, since it would go ahead and take first call from the function and employ that until python is restarted.

What you do seems like the very first time is correct because its the very first time the vista was known as. It had been incorrect sometimes since it got that same date again. It was at random correct again since your apache most likely began another worker process for this, and also the craziness most likely happens when you are getting returned among which process was handling the request.

I discovered that putting wsgi in daemon mode works. Unsure why, however it did. Appears like a few of the recently produced processes will get time messed up.

Maybe the server is evaluating the datetime.now() at server start, try which makes it lazy via a template or make use of a variable inside your view.

Have a look only at that blog post.

you may want to specify this content type like so

def servertime():
  return HttpResponse( datetime.now(), content_type="text/plain" )

also try this:

it might not work because datetime.now() returns a datetime object. Do this:

def servertime():
  return HttpResponse( str(datetime.now()), content_type="text/plain" )

Django sets the machine time zone according to your configurations variable TIME_ZONE. This leads to a myriad of confusion when running multiple Django instances with various TIME_ZONE configurations.

This is exactly what Django does:

os.environ['TZ'] = self.TIME_ZONE

The above mentioned answer:

"I discovered that putting wsgi in daemon mode works"

doesn't work for me personally...

I believe I am choosing not using django's built-in TIME_ZONE any longer.

datetime.now() is most likely being examined once, whenever your class is instantiated. Try getting rid of the parenthesis to ensure that the function datetime.now's came back after which examined. I'd an identical problem with setting default values for my DateTimeFields and authored up my solution here.