Flask Redirect and Errors
- redirect() function - Redirects the user to some specified URL with the specified status code.
- Location - It is the URL where the response will be redirected.
- Status-code - It is the status code that is sent to the browser's header along with the response from the server.
- Response - It is Instance of the response which is used in the project for future requirements.
- In the example, the URL '/' contains a link to the login page as shown in the following screenshot.
- If we click the login then, the application shows the login page. The user enter the data email id and password and the submit button redirects the user to URL /validate.
Flask Redirated Login
- The user is redirected to the URL /success only if the password entered by the user to 'jtp'
Flask Dir Sucess
Standard HTTP Codes
- The following HTTP codes are standardized.
- The default status code is HTTP_302_FOUND.
- abort() function - It is used to handle the cases where the errors are involved in the requests from the client side, such as bad requests, unauthorized access and many more.
- The following error codes depending upon the specified errors.
- 400: for bad requests
- 401: for unauthorized access
- 403: for forbidden
- 404: for not found
- 406: for not acceptable
- 415: for unsupported media types
- 429: for too many requests
Now modify the script login.py from the above code and use the abort() function with the error code 401 (for unauthorized access) in the case of any random password entered by the user.
Flask abort() function
If you want to learn about Python Course , you can refer the following links Python Training in Chennai , Machine Learning Training in Chennai , Data Science Training in Chennai , Artificial Intelligence Training in Chennai