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.
Parsing a JSON file for conflicting entries
From the course: Flask Essential Training
Parsing a JSON file for conflicting entries
- To prevent users from overwriting existing data inside of our urls.json, we need to do a check inside of our code to say, hey if this key already exists and has a url, don't update it. So, let's go ahead and move into our app dot pie and here, after we create our url's dictionary, let's check and see if we already have a urls.json file. So, for this, we're going to have to import some code to be able to read this from the file system. So, after our import json, we're going to do an import os.path and we'll use that here to say if os.path.exists and inside of this we need to check for the file. So, we're going to pass in a urls.json which is the name of our file. Then we'll do a colon to say if that is the case, we want to go ahead and open that file. So, similarly, like we see below, we're going to say with and we want to open. The inside of our parenthesis we want to specify the file name which is our urls.json…
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)
-
-
-