Localized date strftime in Django view

Question:

I would like to send localized date in JSON from django view

Normal text translation via

ugettext

is OK

Following code in view has no effect:

translation.activate("ru")
print datetime.now().strtime("%B")

Output is “August”, instead of “Август

I read about python’s “locale” module, but it’s named as thread unsafe

How to force strftime to use django’s locale?

Asked By: Andrew

||

Answers:

Finally i used date filter from django templates:

from django.template.defaultfilters import date as _date
from datetime import datetime

_date(datetime.now(), "d b, D")
Answered By: Andrew
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.