Answer the question
In order to leave comments, you need to log in
Django timezone conversion?
Hello!
tell me in what format you need to pass the time to the template in order to use it correctly ! and is it possible to transfer the value of the time zone to the tag?
Answer the question
In order to leave comments, you need to log in
You need to install the pytz library. And then you can use the following code:
import pytz
from django.utils import timezone
from django.views.generic import TemplateView
class PageView(TemplateView):
template_name = 'page.html'
def get_context_data(self, **kwargs):
context = super(PageView, self).get_context_data(**kwargs)
context['dt'] = timezone.datetime(2000, 12, 31, 12, 0, 0, tzinfo=pytz.UTC)
return context
{% load tz %}
{% timezone "Europe/Paris" %}{{ dt }}{% endtimezone %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question