I have an SQLite database that I want to query. I am using Flask and WTForms to build the query. The search part works fine and passes the information, but the drop down data doesn't seem to work within the query.
I have the following:
@app.route('/', methods=('GET', 'POST'))
def index():
products = get_products()
form = SearchForm()
if form.validate_on_submit():
order_by = form.orderBy.data
item = '%' + form.searchFor.data + '%'
c.execute("SELECT * FROM supplementInfo WHERE (name) LIKE (?) OR (brand) LIKE (?) ORDER BY (?)", (item, item, order_by))
search_results = c.fetchall()
return render_template('index.html', search_results=search_results, form=form)
else:
return render_template('index.html', form=form, products=products)
Here is the form in case it helps:
class SearchForm(FlaskForm):
searchFor = StringField('What are you looking for?',validators=[DataRequired()])
orderBy = SelectField('Order By', choices=[('name', 'Product Name'), ('brand', 'Product Brand'),
('price', ' Product Price'), ('rating', 'Product Rating')])