Skip to Content
Flask Framework Cookbook - Second Edition
book

Flask Framework Cookbook - Second Edition

by Shalabh Aggarwal
July 2019
Beginner to intermediate
302 pages
9h 38m
English
Packt Publishing
Content preview from Flask Framework Cookbook - Second Edition

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. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Writing a Web Application with Flask

Writing a Web Application with Flask

Doug Farrell
Mastering Flask

Mastering Flask

Jack Stouffer

Publisher Resources

ISBN: 9781789951295Supplemental Content