Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140734

retrieve data from database into html using flask

$
0
0

I want to display data from a PostgreSQL database in an HTML web page on clicking a search button. When I search with values of a row I am getting values of all the rows. I want to display the values of that particular row and not that of all the rows.

@app.route("/search", methods=['GET','POST'])
def search():
    if request.method == "POST":  
        course = request.form['book']
        # input_id = request.POST["book"]
        # cur = conn.cursor()
        try:
            cursor.execute("select course_id,course_name  from course where course_id < 5;",(course))
        except Exception,e:
            conn.rollback()
        else:
            conn.commit()
        data = cursor.fetchall()
        # if len(data) == 0 and course == 5:
        #     cursor.execute("select course_id,course_name from course;",(course_id,))
        #     conn.commit()
        #     data = cursor.query.all()

        return render_template('search.html', data=data)
    return render_template('search.html')
if __name__ == "__main__":
 from flask_sqlalchemy import get_debug_queries
 app.run(debug=True)

    enter code here


Viewing all articles
Browse latest Browse all 140734

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>