Python 将一个函数的返回参数值传递给另一个函数
我想将一个值从一个函数返回到另一个函数,并使用它来筛选我的excel。 下面是我试图做的:Python 将一个函数的返回参数值传递给另一个函数,python,flask,Python,Flask,我想将一个值从一个函数返回到另一个函数,并使用它来筛选我的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 f
@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 %}
我想你想要的是这样的:
<form action="{{ url_for('postfields', sheet_name=val) }}" 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 %}
然后将功能更改为:
@app.route('/postfields/<sheet_name>', methods=['POST'])
def postfields(sheet_name):
# 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=sheet_name)
您可能需要稍微更改sheet_name=val部分,因为我不确定val可能是什么类型的对象,或者它可能具有什么属性。只需确保您正在发送函数所需的数据,并且您的函数已设置为接收您发送的数据类型。必须将HTML中的表单配置为将表单数据发布到第二个端点。我已附加了HTML代码,请您建议必要的更改@MiguelChange action属性以指向您的postfields路由,然后在该路由中添加表单args的处理。