I want some search feature in my website. In the output page, I am getting all the results in single page. However, I want to distribute it to many pages (i.e. 100 searches/page
Function parameters are mapped only to the route variables. That means in your case, the show_results
function should have only one parameter and that's labelname
. You don't even have to default it to None
, because it always has to be set (otherwise the route won't match).
In order to get the query parameters, use flask.request.args:
from flask import request
@app.route('/my_search/<labelname>')
def show_results(labelname=None):
results1 = request.args.get('results1', '0-100')
...
Btw, you better not construct your SQL the way you do, use placeholders and variables. Your code is vulnerable to SQL injection. You can't trust any input that comes from the user.
The correct way to do this depends on the actual database, but for example if you use MySQL, you would do this (not that I'm not using the %
operator):
sql = ".... LIMIT %s, %s"
g.db.execute(sql, (limit_offset, limit_count))