mardi 6 octobre 2015

Dropdown List from (Bottle) SqLite

I'm tring to do my first web app using python 3.4 and Bottle.

I'm tring do create a dropdown list using data from one table colled "Documenti" (using sqlite) The table used has only two columns: ID_D (id) and Documents (name of document). My need is that when a value is choosed, and the botton "search" cliked, Bottle opens a new page, using the ID_D value from the first table and printing info from a second table (colled "Master") thet has also a column colled ID_D.

I'm tring to do this using these codes:

first page with dropdwon list (using first table)

@route('/doc')
def Document():
    conn = sqlite3.connect('db.db')
    c = conn.cursor()
    result = c.execute("SELECT ID_D FROM documenti;").fetchall()
    c.close()
    output = template('doc', rows=result)
    return output

Second page, opened using the ID_D from the previous page to print info from the second table

@route('/docx', method='GET')
def docx():
    if request.GET.get('search','').strip():
        id = request.GET.get('docx', '').strip()
        conn = sqlite3.connect('db.db')
        c = conn.cursor()
        c.execute("SELECT * FROM master WHERE ID_D LIKE ?;" (id))
        result = c.fetchall()
        c.close()
        output = template('doc3', rows=result)
        return output

Here there is my html code used...

in the page with the dropdown list:

<form action="/docx" method="GET">
<select name="docx"><option selected="selected" value="">Seleziona</option>
%for row in rows:
    <option value="{{row}}">{{row}}</option>
%end
</select>
<input type="submit" name="search" value="search">

In the second page (where i wont to see info from the second table using as filter ID_D:

<table border="1">
%for row in rows:
  <tr>
  %for col in row:
    <td>{{col}}</td>
  %end
  </tr>
%end
</table>

My codes doesn't work...the second page is blank...

Thanks to all for your help! Mauro

Aucun commentaire:

Enregistrer un commentaire