Skip to content Skip to sidebar Skip to footer

Django: Datetimefield Taking Utc Format Only, Not Others

The time that is being inserted in database is default UTC, not the timezone based time..I do not understand why is this happening, even though I am particularly specifying, in the

Solution 1:

You can create a middleware that handles the conversion of date and time, import pytz

from django.utils import timezone
from django.utils.deprecation import MiddlewareMixin

classTimezoneMiddleware(MiddlewareMixin):
    defprocess_request(self, request):
        tzname = request.session.get('django_timezone')
        if tzname:
            timezone.activate(pytz.timezone(tzname))
        else:
            timezone.deactivate()

and then you can as easily create the view with the conditions that you indicated earlier. Best if you read the documentation as Kevin suggested.

Post a Comment for "Django: Datetimefield Taking Utc Format Only, Not Others"