How To Update The Database - Python and Flask #9

Sdílet
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.

Komentáře • 39

  • @mostmojo
    @mostmojo Před 3 lety +4

    Awesome teaching style. Wish there was more Flask related content from you! ^.^ Went through many tutorials but yours really helps grasp the concepts

    • @Codemycom
      @Codemycom  Před 3 lety +2

      Thanks! I'm planning a Flask course soon

    • @mostmojo
      @mostmojo Před 3 lety +1

      @@Codemycom awesome!

    • @mostmojo
      @mostmojo Před 3 lety

      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

    • @Codemycom
      @Codemycom  Před 3 lety +1

      @@mostmojo sounds about right

  • @ankan1622
    @ankan1622 Před 3 lety

    Thank you soooooooooo...oo much. Your way of teaching is the simplest.

  • @sjwang3892
    @sjwang3892 Před rokem

    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..

  • @Borisaavedra
    @Borisaavedra Před 4 lety +1

    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!

  • @eshaangupta4101
    @eshaangupta4101 Před 3 lety +1

    I always give a thumbs up for the CZcams algorithm haha

  • @jesusloaiza3032
    @jesusloaiza3032 Před 3 lety

    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.

  • @frankvillalobo981
    @frankvillalobo981 Před 2 lety

    Awesome video man, you saved my life

  • @teclote
    @teclote Před 11 měsíci

    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.

  • @idk____idk6530
    @idk____idk6530 Před 3 lety

    I wnat to ask one thing How I can become like you. . GOD Of Python .. ( Some tip's) From your side ..

    • @Codemycom
      @Codemycom  Před 3 lety

      Ha, watch all the videos on my channel and do all the projects.

  • @akramelomrani8728
    @akramelomrani8728 Před 3 lety

    Thank you sir

  • @Codemycom
    @Codemycom  Před 4 lety

    ▶️ 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

  • @utkuelhan6927
    @utkuelhan6927 Před 3 lety

    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!

  • @jorgcowboy
    @jorgcowboy Před 3 měsíci

    thx

  • @IamWillPowers
    @IamWillPowers Před 3 lety

    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?

  • @MrSharkrat
    @MrSharkrat Před 3 lety

    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 :)

  • @sijioyenekan2657
    @sijioyenekan2657 Před 3 lety

    what if you get a 400 error saying that the term 'name' was not understood, bad request

  • @davidbeiler6364
    @davidbeiler6364 Před 2 lety

    what if i want to remove a friend?

  • @DANNYBANE123
    @DANNYBANE123 Před 4 lety +1

    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.

    • @Codemycom
      @Codemycom  Před 4 lety +1

      No sorry, I don't work with other people's code.

    • @DANNYBANE123
      @DANNYBANE123 Před 4 lety +1

      @@Codemycom Can you please atleast give me an advice about what master is in the constructor?

    • @kyrierevival3658
      @kyrierevival3658 Před 4 lety +1

      why don't you google it?