Django returning wrong time in the template, why?

Asked

Viewed 194 times

0

I saved in my bank a date, in a field of the kind datetime(6), the date saved in the database is: 2020-05-13 14:13:50.000000, however, when I try to print this date in the template using {{ user.time_vip }} I have as return 13 de Maio de 2020 às 11:13, note that the time does not match the time that is saved in the database.

Why is this happening?

My settings.py is configured like this:

LANGUAGE_CODE = 'pt-BR'

TIME_ZONE = 'America/Sao_Paulo'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Taking advantage, how could I verify that this date (time) is bigger than today? Example:

{% if user.time_vip >= timezone.now %}
<span class="d-block mb-3 mt-3 small text-success">Você é vip até {{ user.time_vip }}</span>
{% else %}
<span class="d-block mb-3 mt-3 small text-danger">Você não é vip</span>
{% endif %}

This was an example, it doesn’t work because it returns me a string as I could do it?

1 answer

1


The documentation explains this definition:

Internationalization

https://docs.djangoproject.com/en/2.0/topics/i18n/

To show the date and time of South America just edit the settings.py:

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Cuiaba' 

USE_I18N = True

USE_L10N = True

USE_TZ = False
  • I just kept TIME_ZONE = 'America/Sao_Paulo' and I became USE_TZ = False, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.