IntComma without RequestContext

23 views
Skip to first unread message

Michael Newman

unread,
Oct 27, 2015, 7:37:34 PM10/27/15
to Django users
I am feeling a little lost, a project that I have used intcomma in reliably on an update suddenly stopped getting the commas inserted. This is for an out of request cycle email.

Attempting activate the language doesn't seem to change anything. Am I missing something simple here?

>>> from django.contrib.humanize.templatetags.humanize import intcomma
>>> intcomma(1000)
u'1000'
>>> intcomma("1000", use_l10n=False) #not sure how to do this in templates
u'1,000'
>>> from django.utils.translation import activate, get_language
>>> get_language()
u'us-en'
>>> activate("us-en")
>>> intcomma("1000")
u'1000'

Siim Märtmaa

unread,
Oct 27, 2015, 8:54:08 PM10/27/15
to django...@googlegroups.com
Your language string is backwards:

>>> activate("en-us")
>>> intcomma(1000)
'1,000'

>>> activate("en")
>>> intcomma(1000)
'1,000'


use_l10n=False in a template is:

{% load l10n %}

{% localize off %}
{{ value }}
{% endlocalize %}

https://docs.djangoproject.com/en/1.8/topics/i18n/formatting/#localize
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/30892a71-1a41-488e-b9f9-3d71cfc6abcb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Michael Newman

unread,
Oct 28, 2015, 10:36:19 AM10/28/15
to Django users
Thank you. Knew I was missing something easy.
Reply all
Reply to author
Forward
0 new messages