Using flask to generate a new page display dataframe based on chosen option from HTML

Viewed 54

[1]: https://i.stack.imgur.com/bE3Dp.png

I am new to flask and I have a new HTML page with multiple select box like this. What I want to do is using the string from select box returned from that page to generate a new page display the result run by pandas. But I got some problem. I didn't get the result from select box and I need to post as many as selected tables to the new page if there is. Hope you can give me some advice

app.py

from flask import request, Flask, render_template,url_for,redirect
from markupsafe import escape
import numpy as np
import pandas as pd


app=Flask(__name__)
@app.route("/sub/<name>", methods = ['GET', 'POST'])
def sub(name):
    return render_template('sub'+name+".html",name=name)

@app.route("/out/<name>", methods = ['GET', 'POST'])
def out(name):
    f1=pd.read_csv("test.csv")
    select = request.form.get('subselect1')
    if "邮箱" in str(select):
        result1=f1["邮箱"].str.contains("@")
    if "工号" in str(select):
        result2=f1["工号"].str.isdigit()
    return render_template('out'+name+".html",name=name,  tables=[result1.to_html(classes='data')], titles=result1.values)

form in sub1

<form name="subselect1" id="form" action="" method="post" action="{{url_for('out',name=1)}}">
                <label for="standard-select">Standard Select</label>
                <div class="select">
                    <select id="standard-select" multiple>
                <option value="邮箱">邮箱</option>
                <option value="工号">工号</option>
                <option value="姓名">姓名</option>
                <option value="居住地址/户籍地址">居住地址/户籍地址</option>
                <option value="Option 5">Option 6</option>
                <option value="Option length">
                  Option that has too long of a value to fit
                </option>
              </select>
                    <button type="submit" class="btn btn-default">Go</button>
                </div>
                <div>长按CTRL加选择进行多选</div>
                <!--Input of any type and textareas goes in here-->
            </form>

out1.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>

    {% for table in tables %} {{titles[loop.index]}} {{ table|safe }} {% endfor %}
</body>

</html>
0 Answers
Related