How To Update The Database - Python and Flask #9
Vložit
- čas přidán 7. 09. 2024
- In this video I'll show you how to update the database in Flask.
So we've created a friends list in our database, and we output those names on our friends page. What do we do if we want to update one of those friends? That's what we'll look at in this video.
We'll create a new update.html page that we can link to from each friend. We'll pass the friend's ID to that page where we can update it and save the change to the database.
Awesome teaching style. Wish there was more Flask related content from you! ^.^ Went through many tutorials but yours really helps grasp the concepts
Thanks! I'm planning a Flask course soon
@@Codemycom awesome!
Would it be good to think of this video in this sequence of events to help me understand the "POST" side of things (I think I'm very close! 😊):
1) friends.html ( -- which has an href `/update/{{ friend.id }}` -- ). On click, you go knocking to the update.html, holding the "id" of your selected friend
2) update.html - displays your friend's name in the box. On submit it calls the app.py update(id) method
3) app.py - update method queries the database to fetch all data related to your friends id, stores it in friend_to_update variable, checks to grab the 'name' from update.html, if the value has been changed and commits to the db
@@mostmojo sounds about right
Thank you soooooooooo...oo much. Your way of teaching is the simplest.
glad you enjoy it!
Great content! Really helped me out getting the idea of how flask and database works. I like how you explained all the links between the py file and html template. Cleared my many doubts of what goes from where to where as a beginner..
Happy to hear it!
You are the best! I was trying to use the method "url_for" to submit the change (in other project) and I was getting frustrated. Thanks a lot for this nice and easy solutions! Greetings from Venezuela!
You're welcome!
I always give a thumbs up for the CZcams algorithm haha
Happy to hear it!
Hi John, thanks for your teaching enthusiasm!! Is refreshing and so great to enjoy your energy.
Would you care to explain a similar database update concept: bulk updates. Let's say from a list of items, those with a checkbox clicked would update the database column "show" to True. It would be greatly appreciated.
Awesome video man, you saved my life
happy to hear it
If you have spaces in your data, make sure you have the quote, as John does: value="{{ friend_to_update.name }}"
Html specs do not allow for spaces in attribute names.
I wnat to ask one thing How I can become like you. . GOD Of Python .. ( Some tip's) From your side ..
Ha, watch all the videos on my channel and do all the projects.
Thank you sir
Welcome
no
@@sahmed9143 What ?
▶️ Watch Entire Flask Playlist ✅ Subscribe To My CZcams Channel:
bit.ly/2TU96lm bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
Really appreciate all your videos they are great. It's awesome that you stop and explain everything you do and why. I only have one question I was trying to practice everything you've been through in this series and while I was practicing, I got an error so I tried to do everything as you did. Even though I did everything as you did I'm still getting "jinja2.exceptions.UndefinedError: 'friend_to_update' is undefined" error. Any ideas why? Thank you!
thx
Welcome
Do you really code that fast? Your cursor moves so fast and you work so efficiently. Is that why you use sublime? Is it faster than vscode?
The videos are edited
great video, as always! I love it!
just a question: I try to get a boolean value in ma database, (ON= db.Column(db.Boolean , nullable = False, default = 0)) but i can't update it. I just get the error sqlalchemy.exc.StatementError: (builtins.TypeError) Not a boolean value: '1'. Did you know why?
thanks a lot John :)
what if you get a 400 error saying that the term 'name' was not understood, bad request
what if i want to remove a friend?
Go for it
Love your courses and your videos are very helpful too and i have a doubt.
Sir I am a beginner in python can you please make a in dept tutorial video on this calculator code i found
github.com/JoonaFinland/CZcams/tree/master/Python%20Projects/Calculator
I don't understand the use of master in the constructor could you please explain.
No sorry, I don't work with other people's code.
@@Codemycom Can you please atleast give me an advice about what master is in the constructor?
why don't you google it?