How To Display Data From Database In HTML Table Using Python?

Asked 5 months ago
Answer 1
Viewed 1176

The code for my task is in and for search is in search.html. In spite of having information in the data set, raising a ruckus around town button yields no outcomes. The record lays out an association with the information base. The attempt/aside from block may not be required in the fundamental python code. The HTML code is additionally included. The arrangement is to eliminate the assertion prior to returning the delivered format record.

Python and Jar, show information out of mysql DB on html page


Whenever I endeavor to show my data from MySQL data set onto a html website page, it exclusively displays either the underlying segment of the record or exclusively the section's name.

For instance:



id  names
1   YourQuorum
2   Discussion

@app.route("/db", methodes = ["POST", "GET"])
def db():
    if request.method == "POST":
        cur = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
        cur.execute("SELECT names FROM db WHERE id = 1")
        output = cur.fetchone()
        cur. close 
        return render_template("db.html", data = output)
        return render_template("db.html")


{% extends "base.html" %}
{% block title %}db{% endblock %}
{% block content %}


{% for i in data %}

{% endfor %}

{% for i in data %}

{% endfor %}
{% endblock %}

Yield 1 = {'names': 'YourQuorum'}

Yield 2 = names

Yield 3 = n

How might I recover just the records and prohibit the section name? For example, assuming that the result is "Harry".

As a novice, I would see the value in a concise clarification.

Arrangement 1:

In Python, looking into a dictionary is conceivable.

There have been adjustments made to your code in db.html.

{% extends "base.html" %}
{% block title %}db{% endblock %}
{% block content %}


{% for key, value in data.items() %}

{% endfor %}
{% endblock %}

Answered 5 months ago Tove Svendson