Open Javimetro opened 7 months ago
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
# Configure SQLAlchemy with MariaDB
#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://username:password@host:port/dbname'
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:Supervote50000@localhost/votingsystem'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Optionally, to suppress a warning
db = SQLAlchemy(app)
I've modified the code so the credentials are not hard coded in the main file. The credentials are now moved to an external file isdProjectImports/credentials.py
and are defined thus:
dbUsername = ''
dbPassword = ''
dbHostname = ''
dbPort = ''
dbName = ''
The modified app.config URI:
from isdProjectImports import credentials
app.config['SQLALCHEMY_DATABASE_URI'] = f'mysql+pymysql://{credentials.dbUsername}:{credentials.dbPassword}@{credentials.dbHostname}:{credentials.dbPort}/{credentials.dbName}'
This code configures the main app to get connection with the database. The code would typically be added to app.py file Requires SQLAlchemy
Username: root Password: Supervote50000 Name of DB: votingsystem