SQLite database in flask API Python- P5 | Flask tutorials

Поділитися
Вставка
  • Опубліковано 10 вер 2024
  • #python #python3 #pycharm #flask #python_tutorial #api_in_python #python_framework
    In this video, we integrated the SQLite database in flask API Python to the Books API we created during our previous video. In upcoming videos, we will integrate an online MYSQL database into this API. So, stay tuned!
    You can find the related code at:
    gist.github.co...
    ☕ Buy me a Coffe:
    www.buymeacoff...
    ❤️ If you find my content helpful, become a channel member -
    ua-cam.com/users/py...
    👍 ====== Join us on Facebook: =======
    / pythonist.org
    ===== Visit my website =======
    pythonist.org

КОМЕНТАРІ • 50

  • @Pythonist
    @Pythonist  4 роки тому +9

    Your feedback is truly important to me. So, bombarded me with your quires, questions, and criticism. And, smash the like button 👍

    • @javiermanjarresbaldovino2394
      @javiermanjarresbaldovino2394 3 роки тому

      hi!! I realised all but not show connection with database nor table this is image.. help pleasee!!
      mega.nz/file/4Zgy1aqa#Mp6ozE61IRjKR16iLkjhXL3uTgYEAl8j1NWS1je61hk
      not allow to do Post because no show columns nor name of columns.

  • @janvikalra_
    @janvikalra_ 3 роки тому +6

    One of the simplest, most clear videos out there on using sqlite with flask. Thank you!!

    • @Pythonist
      @Pythonist  3 роки тому

      Glad you liked it, stay tuned!

  • @user-hi9yo4dt3r
    @user-hi9yo4dt3r Рік тому +3

    Hello from Ukraine. Thank you very much for your lessons. You are very good teacher.

  • @abhinavdubey_7
    @abhinavdubey_7 Рік тому +1

    hello, dear Abdul you are a great man , you increase the value of a Muslim man in my heart.

  • @yousefhdaib6854
    @yousefhdaib6854 4 роки тому +5

    Awesome content! waiting for the MySQL part

    • @Pythonist
      @Pythonist  4 роки тому +1

      Stay tuned, Coming soon!

  • @user-ui6ni8lw9l
    @user-ui6ni8lw9l 3 роки тому +6

    Hi where did you get the "cur" variable in line 37 ? It doesn't seem to be defined anywhere .
    Should it be cursor instead of cur ?
    Thanks

    • @Pythonist
      @Pythonist  3 роки тому +2

      yup, there's a typo :)

  • @TheLFDream
    @TheLFDream 3 роки тому +3

    I really like the pacing of your videos, it's great content!

    • @Pythonist
      @Pythonist  3 роки тому

      Glad you enjoy it! stay connected!

  • @user-ro9jb1vs2z
    @user-ro9jb1vs2z 4 роки тому +2

    Thank you very much!

  • @Nohope__
    @Nohope__ 18 днів тому

    Thanks for the video.
    Why didn't you use flask_restful?

  • @kmishy
    @kmishy 2 роки тому +2

    what is the effect of get or post method? we can insert data in table with get method too..

    • @Pythonist
      @Pythonist  2 роки тому +2

      Yup, you can.
      But there's some differences between them, for example GET include all required data in the URL but POST submits data to be processed (e.g. from an HTML form) to the identified resource.

  • @junior75980
    @junior75980 4 роки тому +2

    Good videos! Great content!

    • @Pythonist
      @Pythonist  4 роки тому

      Glad you like them, stay tune!

  • @MrChester114
    @MrChester114 4 роки тому +2

    You never close connection to database. Isn't that a problem?

    • @Pythonist
      @Pythonist  4 роки тому

      It's always a good practice to close the connection to database, I forget if during the tutorial, but it doesn't effect the program at all, connection will automatically close on program exit.

  • @BillyTalentIIIlyrics
    @BillyTalentIIIlyrics 3 роки тому +1

    I'm having currently some issues with the PUT requests. I tried to double check everything but I think, i won't find it on my own. I managed to GET the entries by ID but as soon as i am using the PUT commands, the response is 200 but i get an empty json. Also nothing changes in the DB. For a better learning curve, i try to do it with my own db:
    if request.method == 'PUT':
    sql = 'UPDATE user SET username=?, password=? WHERE id=?'
    up_username = request.form['username']
    up_password = request.form['password']
    updated_user = {
    "id": id,
    "username": up_username,
    "password": up_password,
    }
    db.execute(sql, (up_username, up_password, id))
    db.commit()
    return jsonify(updated_user)
    Any ideas? Thanks!

    • @Pythonist
      @Pythonist  3 роки тому

      It seems you are missing the 'id'

  • @ellixt4187
    @ellixt4187 3 роки тому +2

    Good video! But how would I check the body instead of the form because when I change it to the body, it errors!

    • @Pythonist
      @Pythonist  3 роки тому

      You can access you data from request body directly in the form of JSON, like you can say: req_data = request.get_json(), then you can get access all params.

  • @latinbishop1722
    @latinbishop1722 4 роки тому +1

    something stragen happens during put http --form PUT 127.0.0.1:5000/books/6 author=RBG language=english title=java return looks good but then when i get all books values are changed {
    "author": "english",
    "id": 6,
    "language": "java",
    "title": "RBG"

    • @Pythonist
      @Pythonist  3 роки тому

      Pass values in the same order.

    • @dominikbraun1764
      @dominikbraun1764 3 роки тому +1

      @@Pythonist nope ..
      I guess it's the flawed mapping in the oder of these two statements:
      Line 58 Line 73
      FIX one of those and you'll be good ;-)

  • @dhawalsalvi8079
    @dhawalsalvi8079 6 місяців тому

    What is the difference between conn.execute() and cursur.execute()

  • @god.hand.
    @god.hand. 4 роки тому +2

    May be flask_sqlalchemy would be better to perform these operations.

    • @Pythonist
      @Pythonist  4 роки тому +2

      yup, you are right but have a learning curve.

  • @magrigsdesign8469
    @magrigsdesign8469 10 місяців тому

    thanks bro

  • @vinoths7140
    @vinoths7140 Рік тому

    Amazing Video, can you help me understand @8.56 - should we type cursor.execute or conn.execute?

  • @shritamkumarmund5273
    @shritamkumarmund5273 4 роки тому +2

    Hey, It has been a month we have not seen the next video for this series. Let us know bout your plan to upload. :D

    • @Pythonist
      @Pythonist  4 роки тому +1

      I'm sorry to hear that. Actually, I'm working on a course for a company. Working on the next video... you will get it very soon... stay tuned!

  • @masterhipster8358
    @masterhipster8358 2 роки тому +1

    if request.method == 'POST':
    new_title = request.form['title']
    sql = cursor.execute("INSERT INTO books (title) VALUES (?)",(new_title,))
    # new = (sql, (new_title,))
    conn.commit()
    return f'{sql.lastrowid} created...'

    • @Pythonist
      @Pythonist  2 роки тому

      What's wrong here? What's the question?

  • @rizqimaulana8790
    @rizqimaulana8790 Рік тому

    why my id table is null? anyone can help me

  • @masterhipster8358
    @masterhipster8358 2 роки тому +1

    West of time connection not connected with db and not answer to @Pythonist

    • @Pythonist
      @Pythonist  2 роки тому

      Follow the connection code from the beginning, please!

  • @bradenbigham9875
    @bradenbigham9875 Рік тому +1

    I don't use sqlite...I use open function...

  • @ebosetalee7159
    @ebosetalee7159 3 роки тому +1

    Any tutorial on commit issues cause it doesn't commit

    • @Pythonist
      @Pythonist  3 роки тому

      What are trying to commit? This is a Github gist, you can't commit changes there.

  • @latinbishop1722
    @latinbishop1722 4 роки тому +1

    Can u explain line 23 cursor = ....

    • @Pythonist
      @Pythonist  4 роки тому +1

      The sqlite3.Cursor class is an instance using which you can invoke methods that execute SQLite statements, fetch data from the result sets of the queries.

    • @latinbishop1722
      @latinbishop1722 4 роки тому

      Can’t I do this with con:
      data = con.execute("SELECT * FROM Books”)
      for row in data:
      .......

    • @latinbishop1722
      @latinbishop1722 4 роки тому

      Guesss my question should be when use connections when use cursor

  • @venil82
    @venil82 5 місяців тому

    not even using sqlalchemy?

  • @latinbishop1722
    @latinbishop1722 4 роки тому

    Better video. Is code somewhere

    • @Pythonist
      @Pythonist  4 роки тому

      I will upload code very soon, stay tuned!