- Flask Framework Cookbook(Second Edition)
- Shalabh Aggarwal
- 127字
- 2021-06-24 13:58:09
How it works...
Let's try to understand how the preceding play of methods work.
By default, any Flask view function supports only GET requests. In order to support or handle any other kind of request, we have to specifically tell our route() decorator about the methods we want to support. This is precisely what we did in our last two methods for POST and GET/POST.
For GET requests, the request object will look for args, that is, request.args.get(), and for POST, it will look for form, that is, request.form.get().
Also, if we try to make a GET request to a method that supports only POST, the request will fail with a 405 HTTP error. The same holds true for all the methods. Refer to the following screenshot: