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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Using redirect and url_for for error handling3m 41s
-
(Locked)
Saving to a JSON file5m 6s
-
(Locked)
Parsing a JSON file for conflicting entries3m 11s
-
(Locked)
Alerting users with message flashing5m 26s
-
(Locked)
File uploads from users8m 17s
-
(Locked)
Variable rules in URLs5m 39s
-
(Locked)
Working with static files4m 19s
-
(Locked)
Displaying custom error pages5m 49s
-
(Locked)
-
-
-