简体   繁体   中英

How to pass variable from render in web.py to def in mako

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?

It should be:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM