WebFaction
Community site: login faq

Hello,

Whatever I do, Django does not render my timestamp in any timezone, only gives me UTC. I am using Django 1.6.5, python 2.7 and Postgre. pytz is also installed.

My settings.py

LANGUAGE_CODE = 'en-GB'
TIME_ZONE = 'Europe/Moscow' #This is an example, I have tested a few others, too
USE_I18N = True
USE_L10N = True
USE_TZ = True

The model

from django.db import models
from django.utils import timezone
...
datetime = models.DateTimeField(default=timezone.now)

This is OK, saves 2014-06-20 21:51:46.638251+00:00

The view

I retrieve the "datetime" and it returns 2014-06-20 21:51:46.638251+00:00

The template

{% load i18n %}
{% load tz %}
...
{{ datetime }}
{{ datetime | localtime }}
{{ datetime | timezone:"Europe/Paris" }}
{{ datetime | timezone:"Europe/Moscow" }}

All these return a properly localised date, but still 2014-06-20 21:51:46

Thank you in advance for any help with this.

asked 21 Jun '14, 11:55

tari
3113
accept rate: 0%


I will answer this quickly before I take up anyone's time. The issue "solved itself" (sort of), but apparently a single restart of Apache is not enough. When I change the timezone in settings.py, Django notices it only after Apache has been restarted several times.

Also, {% load tz %} in the template files is not required if I have USE_TZ = True.

permanent link

answered 21 Jun '14, 21:12

tari
3113
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×8
×5
×2

question asked: 21 Jun '14, 11:55

question was seen: 5,219 times

last updated: 21 Jun '14, 21:12

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM