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.
Using redirect and url_for for error handling
From the course: Flask Essential Training
Using redirect and url_for for error handling
- [Instructor] With our new route, we currently are checking to see whether it is a post or a get request, and when it's a get request, we're returning back some text to the user saying this is not valid. Now, this isn't the greatest message for the user. In fact, probably what we want to have happen here is if someone's trying to visit this URL via a get, you should probably just send them back to the home page so that they can then go create their own URL shortener. So let's go ahead and change this to rather than just return text, actually render the home page. So we're going to go ahead and say render_template, and just like we have up here in the home, we are going to say we want the home.html file. So let's go ahead and give this a save, and because we've got our terminal running in development mode, if we go ahead and reload this page, you can see if we go to slash your-url, it takes us home. Now, this is a…
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)
-
-
-