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

Asked 5 months ago
Answer 1
Viewed 1176
1

The code for my task is in project.py 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 dbconnect.py 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

Question:

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:

MyDatabase

db

id  names
1   YourQuorum
2   Discussion

main.py

@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)
    else:
        return render_template("db.html")

db.html

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


{{data}}

{% for i in data %}
    
{{i}}


{% endfor %}

{% for i in data %}
    
{{i[0]}}


{% 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 %}


{{data['names']}}

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


{% endfor %}
{% endblock %}

Answered 5 months ago Tove Svendson