Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How do I display search results on the searchresults page in html using python flask?

Im trying to retrieve information from the database using python flask and display on the html page. The results will be based on the search results typed on the index page form.

This is my python code for search results:

@app.route('/', methods=['POST', 'GET'])
def index():
if request.method == 'POST':
    tagname = request.args.get('search')
    query = "SELECT quote.qid, tags.tagname FROM quote, tags, quote_tags 
WHERE quote.qid = quote_tags.qid AND tags.tagid = quote_tags.tagid AND tags.tagname = '" + str(
        tagname) + "' ;"
    cur = connection.execute(query)
    rv = cur.fetchall()
    cur.close()
    return render_template('searchresults.html', quotes=rv)
else:
    return render_template('index.html')

This is my html index page where the searchbar is located:

<form action="" method='POST'>
    <input type="text" placeholder="Search.." name="search" class="searchbar">
    {% for quote in quotes %}
    <a href="/searchresults.html?search={{quote[1]}}"><img src="../static/SearchIcon.png" Class="searchbar icon"></a>
    {% endfor %}
</form>

This is my searchresults page where i want to display my results based on the tag typed in the searchbar:

    <div class="grid-container2">
        {% for quote in quotes %}
        <div> <a href="/image?id={{quote[0]}}"><img src="../static/{{quote[0]}}.png" class="img"></a></div>
        {% endfor %}
        </div>

The table i am retrieving from the database show the qid(imageid) in the first column and tagname(search criteria) in the second.

please help me retrieve data successfully, Thanks alot.

Comments