Intro to Flask/web frameworks (concept)
Computer Science · Python
Question 1 of 10
0Which IP address is the default host of the Flask development server, meaning it accepts connections only from the same machine?
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
Intro to Flask/web frameworks (concept) explained
A web framework provides the building blocks for a web application, such as receiving requests from a browser, matching each URL to a function and building the response. Flask is a small Python web framework: you write a function for each URL and return what the browser should receive.
A route connects a URL path to a function. The decorator @app.route above a function means that a request for that path runs the function, and whatever the function returns becomes the page. Flask is called a microframework because it includes little by default, and databases, forms and login support come from extra packages. The development server started with the flask run command is meant for testing on your own computer, not for serving real traffic. The framework handles the low-level details of HTTP so you can concentrate on your application's logic.
from flask import Flask
app = Flask(__name__)
@app.route("/hello/<name>")
def hello(name):
return f"Hello, {name}!"
Worked example
Trace a browser request in the code above.
- The browser requests the address /hello/Sam.
- Flask matches the route /hello/, so the function receives name as "Sam".
- The function returns "Hello, Sam!", and Flask sends that text back as the page.
- A request for /hello/Ada would return "Hello, Ada!" instead.
What you will practise
104 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.
Example questions
- Flask is:
- A route in Flask:
- @app.route("/")
- A Flask view returns:
- Flask runs a:
- Which Python statement creates a Flask application object?
- Passing __name__ to Flask(...) helps Flask to find:
- If no methods are specified, which HTTP method does a Flask route accept?
…and 96 more.