Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Nursultan Bolatbayev
Nursultan Bolatbayev
16,774 Points

How to set Timezone in Django?

My timezone is UTC+1. So in settings.py file I configured:

TIME_ZONE = 'Europe/London'
USE_I18N = True
USE_L10N = True
USE_TZ = True

In models.py I have an attribute:

class myModel(models.Model):
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)

When I post some information to this model via Django Rest Framework web interface, the timestamp sets to UTC automatically (which one hour back from my current time zone). But in SQL timestamp is stored with UTC+1 timezone. Very strange behaviour.

How to fix it?

Nursultan Bolatbayev
Nursultan Bolatbayev
16,774 Points

It is very weird, because when I post a data timestamp in SQL is set to UTC+1, but Django Rest Framework shows in UTC. Maybe, Kenneth Love could help me?