3

My django app uses mixture of python's native datetime.datetime.strftime and django's date: filters.

Now, I can change the locale very easily in django using settings.py, but not so easily with python, because I would need to invoke locale.setlocale(locale.LC_ALL, '') somewhere during app startup.

Where should I put this code as it need to be invoked once during startup of django app.

AND is there any better way to handle such situation?

P.S. I cannot do away with using python's native strftime because I need to serialize datetime object somehow.

Vineet Menon
  • 728
  • 2
  • 9
  • 25
  • You should put that code in your `settings.py`, there's nothing wrong with that. However, I have a question for you: what if in the near future you need to support more than a locale? – Andrea Corbellini Dec 28 '15 at 12:03
  • @AndreaCorbellini. Oh! Thanks for the quick answer. Yes, I understand the problem. Do you have any suggestion? As I said, I **need** to serialize `datetime`! – Vineet Menon Dec 28 '15 at 12:08
  • Well, generally when you serialize something, you want it to be locale-independent (e.g. you want to see `06` instead of `June`). I'm not sure what's the relationship between serialization and setlocale in your case, so I can't answer that question – Andrea Corbellini Dec 28 '15 at 12:12
  • @AndreaCorbellini thanks for the suggestions. I serialized my datetime object into iso string and then deserialized at the client end by creating a JS datatime object from the iso string. – Vineet Menon Jan 01 '16 at 05:55

0 Answers0