开发者

Localized date strftime in Django view

开发者 https://www.devze.com 2023-03-26 03:11 出处:网络
I would like to send localized date in JSON from django view Normal text translation via ugettext is OK

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开发者_StackOverflow社区's "locale" module, but it's named as thread unsafe

How to force strftime to use django's locale?


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")
0

精彩评论

暂无评论...
验证码 换一张
取 消