html - Python form drop down options populated by sql -


this first post. new programming. attempting build html form in python contains drop down. drop down options, have hard coded, want populate options sql, dynamically changing if database updated options. must mention drop down being used search/filter data table populated database.

please suggestions.

hard coded dropdown:

<div class="dropdown col-lg-2">   <label for="form_status" id="form_status">status</label>     <select class="form-control input-sm" id="form_status" name="form_status">       <option {% if var_status == ""%}selected="selected"{% endif %} value=""></option>       <option {% if var_status == "1001"%}selected="selected"{% endif %} value="1001">active</option>       <option {% if var_status == "1018"%}selected="selected"{% endif %} value="1018">obsolete</option>     </select> </div> 

code behind search filter

if request.method == 'get':     var_status = ''  if request.method == 'post':      if 'form_status' in request.post , request.post['form_status']:         var_status = request.post['form_status'] 

sql query:

select  distinct "code" status_code, "longdesc" status v_status "code" =1001 or "code" = 1018 order "code"   1001 | active 1018 | obsolete 

how detail need here. have sql query no object storing it. familiar @ running sql queries python? if simple loop , string formatting build options database result.

for line in sqlresponse:     print("<option value='%s'>%s</option>" % (         str(line.status_code), str(line.status)     ) 

if not, without knowing database , library intend use there's no easy answer other around @ basic sql in python tutorials first , decide on framework/library works database. use sqlalchemy orm python.


Popular posts from this blog