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)
2
Answers
I resolved this issue by adding
db.commit()
line after fetching the results.The following was my previous code:
The following is my new code:
You should avoid using pure MySQL connector for handling requests. For
Flask
it is recommended to useFlask-SQLAlchemy
due to possibilities of handling app context.Try installing needed libaries by:
pip install Flask-SQLAlchemy
pip install mysqlclient
Tutorial about Flask-SQLAlchemy: Link to YouTube.