0
我想從一個函數返回一個值到另一個函數,並用它來過濾我的Excel。 下面就是我試圖做的事:傳遞返回參數值一個函數到另一個瓶
@app.route('/bzrules')
def show_tables():
rules = pd.read_excel('static/dummy_data.xlsx')
# User will select value in drop down in view.html. I want the user selection to be passsed to my second function below to filter my excel sheet
subarealist = rules['Subject_Area'].unique().tolist()
return render_template('view.html', subarealist=subarealist)
@app.route('/postfields')
def postfields():
# this is were user selection from first function to pass and help select sheet from my excel
dt = pd.read_excel('static/AllDataSheets.xlsx', sheetname='User selection from subarealist')
下面
是View.html部分代碼:
<form action="{{ url_for('show_tables') }}" method="POST">
<div class="form-group">
<div class="input-group">
<select name='fieldnames'onchange="this.form.submit()">
{% for val in subarealist %}
<option value='{{val}}' selected="search_key" {% if search_key==val %}{% endif%}>{{val}}</option>
<option selected="selected"></option>
{% endfor %}
您必須將HTML中的表單配置爲將表單數據發佈到第二個端點。 – Miguel
我附上了我的html代碼,能否請您建議必要的更改@Migel – totalzoom
將action屬性更改爲指向您的'postfields'路線,然後在該路線中添加對錶單args的處理。 – Miguel