Reputation: 19
I am working on a application. I am using HTML, CSS, Jquery, Flask, MySQL-Python-Connector, Flask-Session. The data will be pushed into the database by some other application and this interface will only be used to view the records in the database. I need to restart the flask application every time a new record is pushed into the database else the old records keep showing up even after infinite page refreshes.
I thought it may be I was using the debug mode while running the application but that does not resolved the issue: app.run(port=5000)
Upvotes: 0
Views: 107
Reputation: 62
You should avoid using pure MySQL connector for handling requests. For Flask
it is recommended to use Flask-SQLAlchemy
due to possibilities of handling app context.
Try installing needed libraries by running:
pip install Flask-SQLAlchemy
pip install mysqlclient
Tutorial about Flask-SQLAlchemy: Link to YouTube.
Upvotes: -1
Reputation: 19
I resolved this issue by adding db.commit()
line after fetching the results.
The following was my previous code:
cursor = db.cursor()
cursor.execute(sql, tuple(params))
results = cursor.fetchall()
The following is my new code:
cursor = db.cursor()
cursor.execute(sql, tuple(params))
results = cursor.fetchall()
db.commit()
Upvotes: 1