So far I have successfully connected my code to the MariaDB database I want to query:
from flask import Flask, render_template, request, flash
import mysql.connector
from datetime import date
import mariadb
app = Flask(__name__)
conn = mariadb.connect(host='IP', port= 3306, user='user', password='password', database='myDatabase')
cursor = conn.cursor()
result = cursor.execute('SELECT * FROM myTable LIMIT 10')
@app.route('/')
def index():
return result
return render_template('index.html')
# run the app.
if __name__ == "__main__":
# Setting debug to True enables debug output. This line should be
# removed before deploying a production app.
app.debug = True
app.run()
How do I get a query to show up on my HTML page of this web app?
return render_template('index.html', data=result.fetchall())and inHTMLyou can usedatawithfor-loop to display it.