Part 1: Using MongoDB with Flask
Howdy! In the last Part of the series, we learned how to create a basic CRUD REST API functionality usi...
For further actions, you may consider blocking this person and/or reporting abuse
Helpful note to everyone, who wants MongoEngine to serialize JSON like this:
not this:
Install MongoEngine GoodJSON library and extend
Movie
class like this:Wow, that's cool. Thank you.
I was doing manual normalization, but this looks awesome.
thanks alot, I really like your style.
about the folder structure - in the begining, is says that the file models.py is inside the database folder, but than later - it says that "models" is the folder: dev.to/paurakhsharma/flask-rest-ap...
which is it?
plus, I'm working with vscode, and in the file "models.py", it doesn't recognize StringField at all. should it? or am I missing something?
Thank you so much, Sorry for the confusion.
models.py is a file. You can see the full code for this part here: github.com/paurakhsharma/flask-res...
I did, thanks. on one hand, it's the most comprehensive flask rest-api tutorial I found online, and that's a lot, really. I could learn in a few days everything I needed. but on the other hand, respectfully, it looks like you just quit after first draft...error handling not working, typos, and no edits regarding comments...
you'll probably spend more time on answering comments...it could be so much more
Yeah you are right, I should update the post for newer version of packages and fix some bugs, typos.
I got distracted with other things so couldn't give much attention to this tutorial. I will try to get some time soon to work on those. Really appreciate your criticism. Thanks! Have a great day.
This is by far the best resource for learning how to do proper JWT Authorization and Authentication in Flask. I've spent hours looking at different tutorials with dubious solutions and not once did I hear about flask_jwt_extended. Thanks a lot!
One thing you might want to update,
@jwt_required
is now@jwt_required()
in newer versions of flask_jwt_extended.Great article,
I tried to make some changes to the parameters of the fields in the document, but it doesn't seem to have any effect
I removed the "required" parameter from the fields and there was no effect. How can changes be made to an existing document?
It's probably because when you give constrains to the field like required, mongodb creates an index for the field. So, to make the change take place you either have to delete the index or easier thing will be to delete the database (don't do that in production 😉)
Please let me know if deleting the index or the database solves your issue.
I had already tried to delete the bank and the index, but I was looking for an alternative to a document that cannot be deleted.
Really helpful,
Some section of the code is omitted here, saved by the complete code on github though.
Thanks again.
Thank you so much ❤️
Can you point me what is missing so that I can add it here.
Missing function definition add_movie()
@app.route('/movies', methods=['POST'])
body = request.get_json()
movie = Movie(**body).save()
id = movie.id
return {'id': str(id)}, 200
.movie not required
from database.models.movie import Movie
Apart from that it's ready to run 😃
I'm getting this error:
TypeError: TopLevelDocumentMetaclass object argument after ** must be a mapping, not NoneType
update
has been resolved by adding force=True
Awesome 👍 Glad that you got it to work. I am not sure how you got this problem. Maybe something to do with your request body?
Nice!
Embedding git diffs, into blog posts? Hmm, that's something I had never thought of before.
I am borrowing that some time!
🤗
Yeah, I thought it would make following the code changes easier 😃
Thank you for this clear explanation.
Can you make the "Flask REST API using Pymongo"?
Using pymongo is almost similar to Mongoengine, mongoengine only makes it easier to do stuffs....
I will try to make one article to show how to use Flask with Pymongo.
Ok. Thank you.
I wish to have configuration structure using PyMongo
Can you please explain-
initialize_db(app)
initialize_db()
is a function that we created inmovie-bag/database/db.py
Which starts the database connection :)