Getting correct local time zone to display for end-users in Django web app

后端 未结 1 1269
孤街浪徒
孤街浪徒 2020-12-12 04:49

I\'m a beginner in Django. Time zone in my settings.py file is set to \'UTC\'. End users of my web app hail from India and Mexico - two very different time zones. I have a c

相关标签:
1条回答
  • 2020-12-12 05:39

    the use of {% localtime on %} is correct, but you need to activate your user's timezone before you can use that. Django does not automatically knows your user's tz.

    https://docs.djangoproject.com/en/1.8/ref/utils/#django.utils.timezone.activate

    # py
    settings.TIME_ZONE = 'UTC'
    timezone.activate('us/estern')
    
    # template
    {% localtime on %}
    {{ datetime }} <= this time will be in estern standard time
    
    0 讨论(0)
提交回复
热议问题