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
Your feedback is truly important to me. So, bombarded me with your quires, questions, and criticism. And, smash the like button 👍
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.
One of the simplest, most clear videos out there on using sqlite with flask. Thank you!!
Glad you liked it, stay tuned!
Hello from Ukraine. Thank you very much for your lessons. You are very good teacher.
hello, dear Abdul you are a great man , you increase the value of a Muslim man in my heart.
Awesome content! waiting for the MySQL part
Stay tuned, Coming soon!
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
yup, there's a typo :)
I really like the pacing of your videos, it's great content!
Glad you enjoy it! stay connected!
Thank you very much!
You're welcome!
Thanks for the video.
Why didn't you use flask_restful?
what is the effect of get or post method? we can insert data in table with get method too..
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.
Good videos! Great content!
Glad you like them, stay tune!
You never close connection to database. Isn't that a problem?
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.
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!
It seems you are missing the 'id'
Good video! But how would I check the body instead of the form because when I change it to the body, it errors!
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.
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"
Pass values in the same order.
@@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 ;-)
What is the difference between conn.execute() and cursur.execute()
May be flask_sqlalchemy would be better to perform these operations.
yup, you are right but have a learning curve.
thanks bro
Amazing Video, can you help me understand @8.56 - should we type cursor.execute or conn.execute?
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
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!
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...'
What's wrong here? What's the question?
why my id table is null? anyone can help me
West of time connection not connected with db and not answer to @Pythonist
Follow the connection code from the beginning, please!
I don't use sqlite...I use open function...
Any tutorial on commit issues cause it doesn't commit
What are trying to commit? This is a Github gist, you can't commit changes there.
Can u explain line 23 cursor = ....
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.
Can’t I do this with con:
data = con.execute("SELECT * FROM Books”)
for row in data:
.......
Guesss my question should be when use connections when use cursor
not even using sqlalchemy?
Better video. Is code somewhere
I will upload code very soon, stay tuned!