dennoh

Flask

Jul 13th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. @app.route('/search/<int:idno>', methods=['GET', 'POST']) #change here
  2. def search(idno):
  3.     results = []
  4.     search_string = request.form['search']
  5.     if request.form['search'] == '':
  6.         qry = db_session.query(idno)
  7.         results = qry.all()
  8.  
  9.     if not results:
  10.         flash('ID not found !')
  11.         return redirect('/')
  12.        
  13.     else:
  14.         # display results
  15.         return render_template('success.html', results=results)
  16.  
  17.  
  18.  
  19.  
  20. <div class="search">
  21.   <form method="POST"> # change here remove action
  22.       <input type=text name=search value="{{ request.form.search}}"></br>
  23.       <div class="actions"><input type=submit value="Search"></div>
  24.   </form>
  25.   </div>
  26.   {% for message in get_flashed_messages() %}
  27.   <div class=flash>
  28.       {{ message }}
  29.   </div>
  30.      
  31.   {% endfor%}
  32.    
  33. {% endblock%}
Add Comment
Please, Sign In to add comment