2017-04-07 7 views
0

ある関数から別の関数に値を戻して、それを使用してExcelをフィルタリングしたいとします。以下 がやろうとしていますものです:1つの関数を別のフラスコに返します。

@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 %}        
        
+0

HTML内にあるフォームは、フォームデータを2番目のエンドポイントに送信するように設定する必要があります。 – Miguel

+0

自分のHTMLコードを添付しました。必要な変更を提案してください。@Miguel – totalzoom

+0

アクション属性を 'postfields'ルートを指すように変更し、そのルートのフォームargsの処理を追加してください。 – Miguel

答えて

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) 

セクションを少し変更する必要があるかもしれません。なぜなら、正確にどのような種類のオブジェクトがあるのか​​、それともどのようなプロパティがあるのか​​わからないからです。関数が必要とするデータを送信していることと、送信するデータの種類を受け取るように関数が設定されていることを確認してください。

関連する問題