0
0
Flaskframework~10 mins

Why understanding request-response matters in Flask - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flask class.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Ajsonify
Brequest
Crender_template
DFlask
Attempts:
3 left
💡 Hint
Common Mistakes
Importing request instead of Flask
Importing render_template when not rendering templates
Importing jsonify when not returning JSON
2fill in blank
medium

Complete the code to create a Flask app instance.

Flask
app = [1](__name__)
Drag options to blanks, or click blank then click option'
Ajsonify
BFlask
Crender_template
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using request instead of Flask
Forgetting to pass __name__
Calling render_template instead of Flask
3fill in blank
hard

Fix the error in the route decorator to respond to the root URL.

Flask
@app.route([1])
def home():
    return "Hello, world!"
Drag options to blanks, or click blank then click option'
A'/'
B'home'
C'index'
D'main'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'home' or 'index' as route strings without slashes
Forgetting quotes around the route string
Using incorrect route paths
4fill in blank
hard

Fill both blanks to access the HTTP method and return it as a string.

Flask
from flask import request

@app.route('/method', methods=['GET', 'POST'])
def method():
    return request.[1]  # returns the HTTP method used

# Example: if client sends POST, returns the [2]
Drag options to blanks, or click blank then click option'
Amethod
Cform
Dargs
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.form or request.args which hold data, not method
Confusing method with other request attributes
5fill in blank
hard

Fill all three blanks to create a dictionary response with the request path and method.

Flask
from flask import request, jsonify

@app.route('/info')
def info():
    data = { [1]: request.[2], [3]: request.method }
    return jsonify(data)
Drag options to blanks, or click blank then click option'
A"path"
Bpath
C"method"
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted keys in dictionary
Using request.url instead of request.path
Mixing up keys and values