python - How can I return multi-column table row values for a url_for using the Jinja2 iterrows function? -


in example below, i'm creating href's each row item in column3 , variable (var1) sent along (which works fine). question how can send adjacent row value using variable (var2) column1? need handled jquery or means?

var2 below what want able do, not sure how to, currently.

table:

       column1    column2    column3 row1   yes        foo        bar  row2   no         foo1       bar3 row3   maybe      foo2       bar2 

app.py:

@app.route('/mypage/<var1>') def python_function(var1,var2):     df = pd.dataframe(lotsofdata)     return render_template('index.html',data=df) 

index.html:

<table id="data"> <thead> <tr> {% c in data.columns.values %}     <th>{{ c }}</th> {% endfor %} </tr> </thead> <tbody> {% index, row in data.iterrows() %}     <tr>         {% v in row %}             <td>             {% if data.columns[loop.index0] in ['column3'] %}                 <a href="{{ url_for('python_function',var1=v,var2=???) }}">{{ v }}</a>             {% else %}                 {{ v }}             {% endif %}             </td>         {% endfor %}     </tr> {% endfor %} </tbody> </table> 

to call function in jinja you'd create global function in __init__.py

def cool_func(var1, var2):     return var1 + var2  # or  app.jinja_env.globals.update(cool_func=cool_func) 

then example replace:

<a href="{{ url_for('python_function',var1=v,var2=???) }}"> 

with:

<a href={{ cool_func(var1, var2) }}> 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -