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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -