Jinja2 Stars Filter for Bootstrap
@app.template_filter('stars')
def _jinja2_filter_stars(value):
"""
Adds filled and empty stars
Usage: {{ obj.stars|stars|safe }}
"""
ret = ""
if value:
for i in range(1, value+1):
ret += '<i class="icon-star"></i>'
for i in range(value, 5):
ret += '<i class="icon-star-empty"></i>'
return ret
Written by Alejandro Ayuso
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#