- Flask Framework Cookbook(Second Edition)
- Shalabh Aggarwal
- 117字
- 2021-06-24 13:58:05
How it works...
In the beginning, the database is empty and has no products. This can be confirmed by opening http://127.0.0.1:5000/products in a browser. This would result in a 404 NOT FOUND error page.
Now, first we would want to create a product. For this, we need to send a POST request, which can easily be sent from the Python prompt using the requests library:
>>> import requests >>> requests.post('http://127.0.0.1:5000/product-create',
data={'name': 'iPhone 5S', 'price': '549.0'})
To install the requests library, run pip3 install requests in your Terminal.
To confirm whether the product is now in the database, we can open http://127.0.0.1:5000/products in the browser again. This time, it would show a JSON dump of the product details.