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

Using redirect and url_for for error handling

From the course: Flask Essential Training

Start my 1-month free trial

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…

Contents