Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I display a SQL table in flask?

Is there a way I can display a SQL table in HTML and CSS using flask? If so please leave the code down below, or make a GitHub directory so I can have a look!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is what I used in my older projects while using Microsoft SQL.

###### IMPORTED LIBRARIES ######  
from flask import render_template, Flask
import pyodbc

###### SQL CONNECTION ######
connection = pyodbc.connect('Driver={SQL Server};'
                      'Server=DESKTOP-NP0I4J5\SQLEXPRESS;'
                      'Database=REPLICATED_STORAGE;'
                      'Trusted_Connection=yes;')

cursor = connection.cursor()    
cursor.execute("SELECT * FROM FRUITS")
data = cursor.fetchall()

###### FLASK SERVER ######
headings = ("COLOR", "TYPE", "NAME", "WEIGHT")
id = 80809915

app = Flask(__name__)
@app.route('/')    
def index():    
    return render_template("table.html", headings=headings, data=data)

if (__name__ == '__main__'):
    app.run()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading