lundi 27 février 2017

Return value from select tag flask/jinja

I'm attempting to have a variable returned to my python code on clicking a select from a dropdown box - to generate the post I'm using javascript .submit(). The value would then be used create a mongodb query for which the result would be used to populate another dropdown menu on the same page.

python:

posts = db.posts
name_list = [p['name'] for p in posts.find({'type': "server"})]

if request.form['submit'] == 'myselect':
    choice = x
    sub_name_list = [q['sub_server'] for q in posts.find({'type': choice})]

return render_template("index.html",
                       title='Database selector',
                       user='Bob',
                       server_list=name_list,
                       sub_server_list=sub_name_list)

html/jinja:

  <label>Select1 :</label>
    <select name="option1" id="myselect" onchange="this.form.submit()">
      
    </select>
  </td>

  <td>
    <label>Select2 :</label>
      <select name="option2" id="sub_myselect" onchange="this.form.submit()">
      
  </td>

Thank you in advance for any pointers or advice.




Aucun commentaire:

Enregistrer un commentaire