'Why is this jinja2 for loop not working in pyhtml code?

For example if I use a for loop like this it doesnt detect the line between the loop as pyhtml and gives out "Invalid Syntax" error. Is there some compatibility issue or practices I'm missing.

t = html(
    head(
        title('Student data')
    ),
    body(
        h1('Student Details'),
        table(
            tr(th('Student id'),th('Course id'),th('Marks'))
            {% for d in data[data['Student id']==int(sys.argv[2])] %}
            tr(th('{{Student}}'),th('{{Course}}'),th('{{Marks}}'))
            {% endfor %}
            )
    ))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source