python - models.DateTimeField(auto_now_add = True) -


i have problem models.datetimefield, because i´m méxico , in settings.py use this:

time_zone = 'america/mexico_city' 

but when add register in mysql database, says register added @ 18:00 (4 hours later, because here, in mexico city 14:00)

titulo = models.charfield(max_length = 60) contenido = models.charfield(max_length = 140) fecha = models.datetimefield(auto_now_add = true) 

if enable use_tz = true, django uses utc times in database. why seeing time 4 hours ahead -- utc time.

https://docs.djangoproject.com/en/dev/topics/i18n/timezones/

django has helpers take utc , convert when display in view. try getting object db uses datetimefield , try in view {{ value }} datetime:

{% load tz %}  {% localtime on %}     {{ value }} {% endlocaltime %}  {% localtime off %}     {{ value }} {% endlocaltime %} 

you might have install pytz requirement if haven't done already:

pip install pytz 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -