I'm working on YouTube Data API. I'm trying to display the viewCount from the video statistics in my HTML using jinja2 on Google App Engine.
When I specify constant values like in my template like:
{{ '{0:,}'.format(1234567890) }}
the output works okay as:
1,234,567,890
However, if I specify the code as:
{{ '{0:,}'.format(video_item.statistics.viewCount) }}
It does not work and displays internal server error saying:
{{ '{0:,}'.format(vivi.statistics.viewCount) }}, ValueError: Cannot specify ',' with 's'.
I'm not sure what that means.
However,
{{video_item.statistics.viewCount}}
works correctly. Can someone help me out please? Thanks
@matthias-eisen thankx for your answer. It worked fine. In Jinja2, int(some_string)
does not work. I used:
some_string | int
So for my question, it should be:
{{ '{0:,}'.format(video_item.statistics.viewCount | int) }}
The API passes viewCount as a string (see https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.list?part=statistics&id=I90H3dN2HbI&_h=2&).
Inside the Handler:
view_count = '{0:,}'.format(int(video_item.statistics.viewCount))
Inside the Template:
{{ view_count }}
Also: http://docs.python.org/2/library/string.html#format-specification-mini-language
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With