I am currently using flask and I aim to do the following:
When I click on a tab on my webpage constructed by HTML, I want it to display a list of data stored in mysql server.
I know how to pull the data from sql in Python (using mysql connector) and then 'input' the values individually, however, this would require me to create another webpage with the sole objective of displaying data from that particular tab - and then I'd have to create a new webpage altogether for another tab.
This seems really inefficient and was wondering if there is a way of displaying data from sql when pressing a tab without needing to navigate to another page.
Code
Python:
@app.route('/studentdb')
def sdb():
return render_template('studentdb.html')
HTML (studentdb.html)
<!DOCTYPE html>
<html lang="en">
<head>
<html lang="en">
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='css/style_sdb.css')}}">
<title>Student Database</title>
</head>
<body>
<div class="tab">
<button class="tablinks" onclick="openSubject(event,'bio')">Biology</button>
<button class="tablinks" onclick="openSubject(event, 'chem')">Chemistry</button>
<button class="tablinks" onclick="openSubject(event, 'phy')">Physics</button>
</div>
<div id="bio" class="tabcontent">
<h3>Biology</h3>
<p>Biology Students List</p>
</div>
<div id="chem" class="tabcontent">
<h3>Chemistry</h3>
<p>Chemistry Students List</p>
</div>
<div id="phy" class="tabcontent">
<h3>Physics</h3>
<p>Physics Students List</p>
</div>
<script src="static/js/tabs.js"></script>
</body>
</html>
There are also css and javascript code for the tabs that I have not included - I'm happy to post them if required.
render_template()(i.e.render_template(student_db.html, bio_list = bio_list...)) - so that when I click on each individual tab, the data would have already been processed