My first simple recipe Flask/Postgres app.
I started learning some coding by enrolling in the CS50 class from Harvard on edX and I am now hearing their Web Development class. Long story short, I built an ugly recipe app. The aim for me was to built the whole functionality (logic) and not focus on web design at the moment. The project is on github: www.github.com/O2-AC/recipes
It uses Flask as Backend and Postgres as database. Feel free to try yourself. First run create.py to set up your database (DATABASE_URL must be given as an environment variable). After setting up the database simply run the Flask application.
I would like to get some feedback. It's the first proper app that I build. Currently it is not possible to edit or delete a recipe, but this will come very soon :)
Edit: Check it out running here: http://recipe50.herokuapp.com
Posted Mar 10, 2018, 8:23 PM UTC · edited
In your "view all receipes" route, is there a reason you're building a list the way you are?
https://github.com/O2-AC/recipes/blob/e05ef28d80300aaa31c4211b67db51605ee27b08/application.py#L108-L115
I suspect you could just do
db.session.query(Recipe)to get a list of all the recipes, since that seems like what you're trying to do.On this line, you seem to be referencing
ingredientvariable, but that variable is not defined.https://github.com/O2-AC/recipes/blob/master/application.py#L53
Also the fact that you're doing
db.session.expirein an "add recipe" view tips me off that there might be a better way to do what you're trying to do. You probably don't need to expire the recipe. Just find it by name like you're doing, then update it if it already exists.Thank you so much for the feedback. Regarding your first point, you are absolutely right. I just didn't realize/know that you could get all your items from a table with that code. Regarding the expire(). I think at one point I had some code before this line where I was already adding recipe to the database, but not comitting/flushing. Since I didn't know if this change would persist until the current user would commit something, I thought it would be safer to just get rid of that object. To be honest, I have no idea if that is what "expire()" would achieve or not. But I will definitely use your approach there. Although I won't run the update function here, since this would directly overwrite an existing recipe, which I don't want. I'm trying to write some code at the moment that lets the user edit an existing recipe, which is what I think would be a better solution.