且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将返回参数值的一个函数传递给另一个瓶子

更新时间:2023-11-09 23:34:40

 < 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 subarealist%}

然后将您的函数更改为:

  @ app.route('/ postfields /< sheet_name>',methods = ['POST'])
def postfields(sheet_name ):
#这是用户从第一个函数中选择来传递并帮助从我的Excel中选择工作表
dt = pd.read_excel('static / AllDataSheets.xlsx',sheetname = sheet_name)

您可能需要稍微更改 sheet_name = val ,因为我不确定究竟是什么样的对象 val 可能是,或者它可能有什么属性。只要确保你发送了你的函数需要的数据,并且你的函数被设置为接收你发送数据的类型。

I would like to return a value from one function to another function and use it to filter my excel. Below is what am trying to do:

@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')

below is part of View.html code :

<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 %}       
           

I think what you want is something like this:

<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 %}

And then change your function to:

@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)

You may need to change the sheet_name=val section a bit, because I'm not sure exactly what kind of object val might be, or what properties it could have. Just make sure that you're sending the data your function needs, and that your function is set to receive the type of data you're sending it.