python - Error selecting items from a drop down list using Flask -
i trying create flask app allow me query postgres database. on "data" page. display list of tables in database along top. when select table want drop down list of columns in table appear. want able select variable, bring couple of boxes can define range(min, max, etc) , use button perform query , pull data of interest.
i new flask , app design in general there chance missing simple. using lists fill in until database , running.
i can select table , drop down or list appear. when pick drop down item , hit select bad request error, highlights field.
app.py:
from flask import flask, render_template, request, redirect, url_for, abort, session app=flask(__name__) @app.route('/stack', methods=['get','post']) def stack(): tables=['a','b'] temp_list=[] if request.method == 'post': table_id = request.form['table'] print table_id variable_id =request.form.get('first_select', 'error') if table_id == 'a': temp_list=['a1','a2'] elif table_id == 'b': temp_list =['b1','b2'] print temp_list return render_template('stack.html', tables=tables, temp_list=temp_list ) else: return render_template('stack.html', tables=tables, ) if __name__ == "__main__": app.run(debug=true) stack.html:
<div class=container> <div class='one'> <p>tables</p> <ul class='databases'> {% tbl in tables %} <div class="inner"><li><form action="" method="post"><button class="on" type="submit" name="table" value={{tbl}}>{{tbl}}</button></form></li></div> {% endfor %} </ul> </div> <div class="col"> <p>variables within {{ table_id }}</p> <form method="post" action=""> <div class="dropdown"> <select name="first_select"> {% item in temp_list %} <option value="{{item}}" selected>{{item}}</option> {% endfor %} </select> </div> <button type="submit" class="btn btn-default">select</button> </form> </div> <div class="col"> <ul class='firstlist'> <li>select filters apply {{variable_id}}</li> </ul> </div> </div> basically picking item in drop down list, when hit select button bad request error?
variable_id reads: 'error', there must wrong in how processing select command, don't understand going wrong.
any appreciated.
Comments
Post a Comment