1👍
✅
When rendering templates or using number_format
outside of the Django app flow the translation module is not activated. Here are a few notes and instructions on how to turn on translation in custom management commands.
To make the shell example work we just need to activate the translation module as such:
(venv) $ ./manage.py shell
Python 3.6.4 (default, Mar 1 2018, 18:36:50)
>>> from django.utils.formats import number_format
>>> from django.utils import translation
>>> translation.activate('en-us')
>>> number_format(50000, force_grouping=True)
'50,000'
The key line above is: translation.activate('en-us')
0👍
Everything is ok with your setup I guess. Just set USE_L10N = True
in your settings.py
if it is set to False, as @Tim Schneider mentioned, and you better try it like this {{ val|intcomma }}
as @Leonard2 mentioned and it must work. And also as it is mentioned here make sure:
To activate these filters, add ‘django.contrib.humanize’ to your INSTALLED_APPS setting.
- How to skip using MEDIA_ROOT and MEDIA_URL in a single specific case
- Could not understand foreign key and manytomany field in django
- ReverseOneToOne not evaluated in django signal
Source:stackexchange.com