How to get dropdown list items from pandas dataframe using python flask? How to get dropdown list items from pandas dataframe using python flask? flask flask

How to get dropdown list items from pandas dataframe using python flask?


when you call to_html() method, it will create the html table and you can't iterate over it. I don't know what was your df data, but i think this might work for you.

app.py

@app.route('/api/v1/resources/getservices', methods=['GET'])def api_services():    d = {'Services': ["red", "green", "blue"]}    df = pd.DataFrame(data=d)    return render_template('view.html', table=df)

view.html

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Dropdown</title>    <h1>Services</h1></head><body><select name="table" method="GET" action="/">{% for colour in table["Services"] %}        <option value="{{ colour }}">{{ colour }}</option>    {% endfor %}</select></body></html>