Flask Dashboard Creation Steps
Flask Dashboard Creation Steps
1) config.py
import os
2) models.py
def __repr__(self):
return f"<DataEntry {self.title}>"
3) main.py
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:
%40Abhinavsql123@localhost/dashboard_db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
if __name__ == "__main__":
from models import DataEntry
app.run(debug=True)
4) init_db.py
with app.app_context():
db.create_all()
print("✅ Database tables created successfully!")
5) ## Open MySQL and create the database in the SQL commandline client
6) ## Now create the table named "DataEntry" using this script in the vscode
terminal
7) ## Check in the MySQL commandline client whether the table is created or not
9) ## Since the table is created, we have to insert json data into the table
--> data_loader.py(code):
import json
from main import db, app
from models import DataEntry
10) ## Now run this command to load the json data successfully
12) ## Now we have to create Flask API routes to fetch and display the data in JSON
format.