Using builtin 'str' function in web.py templates: global name not found
Or you can use the construct "%d" to convert ints to string, as:
stringified_int="%d" % n
or in the template style using your question:
$ filename="img[0-%d]" % n
I don't know if this works for python2, but for python3 it works.
I've spent way too much time trying to figure this out:
I'm passing a template a number like so and trying to make it a string:
$def with (num)
$(str(num))
or
$str(num)
This generates an error saying global name "str" not found.
Edit & Solution: I'm doing this so I can refer to "img[0-n].png". If num is passed as a number, you can make this string by just saying "img$(num).png". No need to convert num to string explicitly.