Coding Challenge
Practice creating a route in a Python Flask server.
We'll cover the following
Problem statement
Currently our webserver.py
is a Flask server that serves up user data on two routes, /user/<userid>
and /users
.
For this code challenge:
-
Add a Flask route
/quantity
to thewebserver.py
file. Use a function calledget_quantity()
that returns the total number of users in theuser
list as a JSON string that has a key calledquantity
and the number of users as its value. -
Use the
len()
function to get the quantity of theusers
list.
Note: When we click “Run” below, the widget will ping the
/quantity
route of the Flask server. Make the required changes before clicking “Run” or it will give a404
error.
Get hands-on with 1400+ tech skills courses.