Frage

I'm trying to pass the follwoing

return render('warps.html', query=query)

To a mako template and have it read the query with the follwoing.

<%def name="warps()">
    <%
    warp = db.warps.find('player' : ${query}).sort(u'player', 1)
    print warp
    %>
    %for x in warp:
        ${x['player']},&nbsp;&nbsp;${x['x_origin']},${x['y_origin']}&nbsp;&nbsp;&nbsp;${x['x_dest']},${x['y_dest']}<br />
    %endfor
</%def> 

The ${query} works fine outside of the <% -- %> block but within it has to have "" around it. So if I print it i get ${query} as a string instead of the variable that ${query} is supposed to represent.

Is there a way to pass a render variable from web.py into the python on a mako template?

War es hilfreich?

Lösung

It should be:

warp = db.warps.find('player' : query).sort(u'player', 1)

BTW, you shouldn't put logic in the template.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top