django has a builtin templatetag that you can use in python too that does the exact same thing