Have u placed the db file in the proper directory? I mean both the app.py and db file should be in the same directory and also it’s important to commit and close db operations.
Not always but it depends how your giving the path. If you are giving the right path then there will be no issues. Once check how are giving the path from app.py !
I use utils.py where I can declare all my methods. Utils.py located in a folder called src. That is a folder placed in root directory of app where we have a app.py
Now in utils.py I have a method called load_data()
def load_data() → pd.DataFrame:
“”"
These function query the database and return all records as a DataFrame
returns pd.DataFrame(all_records)…
“”"
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(file)))
db_path = os.path.join(root_dir, “data”, “madurai.db”)
with sqlite3.connect(database=db_path) as con :
statement = “SELECT * FROM donation_records;”
df = pd.read_sql_query(statement,con, index_col=“id”)
return df
Hey @Nagarjun , the logic is correct but how you are calling this in your app.py file?
Also instead of using the os module you can directly use
sqlite3.connect(‘madurai.db’) because you are in the src folder and you can easily call this as
from src.utils import function_name in app.py file
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.