[Flask] commafy filter

Jerry Mccreary jerry.mccreary at mac.com
Fri Apr 15 01:49:07 EDT 2016


There is a Flask interface for the Humanize library. 
https://github.com/vitalk/flask-humanize

It has intcomma filter.

--
Jerry McCreary


> On Apr 15, 2016, at 1:35 AM, Gabor Szabo <gabor at szabgab.com> wrote:
> 
> Hi Jani,
> 
> yes, it seems in Django it is called intcomma.
> I was looking at the custom filters page, but so far I have not managed to make that work.
> 
> I've added the following to the file of my flask application, but I still get  TemplateAssertionError: no filter named 'commafy'
> It is not yet clear to me how do I convince Flask to see it.
> 
> from jinja2 import Environment
> env = Environment()
> 
> def commafy(s):
>     return 42
> env.filters['commafy'] = commafy
> 
> 
> Gabor
> 
>> On Fri, Apr 15, 2016 at 8:26 AM, Jani Šumak <jani.sumak at gmail.com> wrote:
>> Hi Gabor,
>> 
>> you mean something similar to intcomma in Django (https://docs.djangoproject.com/en/1.9/ref/contrib/humanize/#intcomma)? I think not (please correct me if I am wrong), but you can always register your own filters. Take a look at custom filters. 
>> 
>> Hope that helps!
>> 
>> Cheers, Jani
>> 
>>> On Fri, Apr 15, 2016 at 7:06 AM Gabor Szabo <gabor at szabgab.com> wrote:
>>> Hi,
>>> 
>>> is there a filter in Jinja to commafy numbers? That is, to put a comma in-front of ever 3 digits?
>>> 
>>> I could not find one yet, so I've been using this expression all over the place:
>>> 
>>> {{ "{:,}".format( value ) }}
>>> 
>>> but I think it would be nicer if I could write 
>>> 
>>> {{ value | commafy }}
>>> 
>>> 
>>> 
>>> regards
>>>   Gabor
>>> 
>>> 
>>> _______________________________________________
>>> Flask mailing list
>>> Flask at python.org
>>> https://mail.python.org/mailman/listinfo/flask
> 
> 
> 
> -- 
> Gabor Szabo                    http://szabgab.com/
> Code Maven                     http://code-maven.com/
> Perl Maven                       http://perlmaven.com/
> Perl Weekly                      http://perlweekly.com/
> Phone:                             +972-54-4624648
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160415/beab6106/attachment.html>


More information about the Flask mailing list