Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent NUMBER_GROUPING of integers in Django Template

Django has a nice feature to add thousands separators to integers in templates automatically, by setting NUMBER_GROUPING=True. The problem is that for some integers (for instance 'year') you do not want decimal grouping. Somehow I can't find a filter or something else that prevents Django from adding thousands separators to my integers.

Does anyone know what I should do to exclude certain integers from being processed by the NUMBER_GROUPING process, without disabling this functionality for other integers?

Wout

like image 438
Wouter Klein Heerenbrink Avatar asked Sep 12 '11 15:09

Wouter Klein Heerenbrink


People also ask

What is USE_L10N in Django?

Controlling localization in templates When you have enabled formatting with USE_L10N , Django will try to use a locale specific format whenever it outputs a value in a template.

What is Forloop counter in Django?

Django for loop counter All the variables related to the counter are listed below. forloop. counter: By using this, the iteration of the loop starts from index 1. forloop. counter0: By using this, the iteration of the loop starts from index 0.

What does the built in Django template tag Lorem do?

lorem. Displays random “lorem ipsum” Latin text. This is useful for providing sample data in templates.

What is Autoescape in Django?

Definition and Usage The autoescape tag is used to specify if autoescape is on or off. If autoescape is on, which is default, HTML code in variables will be escaped.


1 Answers

The NUMBER_GROUPING setting is part of django's format localization functionality. To get rid of it in a template try {{ value|unlocalize }}. You'll also need to {% load l10n %} beforehand. This also seems to require django 1.3.

See the docs for more info.

like image 62
meshantz Avatar answered Oct 11 '22 11:10

meshantz