将返回参数值传递给另一个烧瓶

时间:2017-04-07 15:22:17

标签: python flask

我想从一个函数返回一个值到另一个函数并使用它来过滤我的excel。 以下是我想要做的事情:

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

以下是View.html代码的一部分:

client

1 个答案:

答案 0 :(得分:0)

我认为你想要的是这样的:

<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究竟是什么类型,或者它可能具有哪些属性。只需确保您正在发送您的功能所需的数据,并确保您的功能设置为接收您发送的数据类型。

相关问题