I will again reiterate, I LOVE databases. I just find the communication between application and the ‘brain’ (so to speak) so much fun. I also think other peoples versions of fun are much different than my own.
With Flask, you have to go about the database in a strange way in my opinion. I am not saying its hard, I just think its weird. Heck, maybe it makes it easier. I have used Mongo database
with Flask a long time ago, I had super fun with Mongo. Anyway, we used SQLite
for this little learning session.
In order for the database to work, we are going to need to update our app.py file (this is a tut on keeping a log of your ‘friends’, hence the name. I am going to build a proper useable application in my next run for all this to stick):
and we are going to initialize our database using SQLAlchemy like this:
Then I created a model for the entries:
Then you run ‘flask run’ in your Terminal and your db is created with the columns that we created in our model. 🙂 Nice!
At this point I needed to create ‘friends.html. (I am doing this at the end of my work on this, so it will contain a lot of information I just skimmed over)
And we have an ‘update.html’ page that uses update section in the code above to redirect to.
And there we go folks. A complete CRUD application.