From the course: Flask Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Saving to a JSON file

Saving to a JSON file

From the course: Flask Essential Training

Start my 1-month free trial

Saving to a JSON file

- [Instructor] The purpose of our URL shortener, is for someone to enter in a website URL, as well as it's nickname or short name for that URL, so they can quickly access it in the future. We need some way to save this information, and Flask is not a great option when it comes to saving data with a database. You have to do all the work yourself. You often end up writing SQL statements. But for this situation, where we just simply have to name what a website URL is, and then what the nickname is for it, an instance like a JSON file would be perfect for saving our data. So lets go ahead and write the code necessary in our app.py so that when someone enters in some information, that we can then save that into a JSON file. So this is going to be the situation when someone is doing a post request. So we'll go ahead and just make a new line here. And the first thing that we want to do is create a dictionary that can store the…

Contents