0
0
Flaskframework~10 mins

How Flask processes HTTP requests - Interactive Practice

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

Complete the code to import Flask and create an app instance.

Flask
from flask import [1]
app = [1](__name__)
Drag options to blanks, or click blank then click option'
Arender_template
BFlask
CRequest
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Request instead of Flask
Forgetting to create the app instance
2fill in blank
medium

Complete the code to define a route for the home page.

Flask
@app.route('[1]')
def home():
    return 'Hello, Flask!'
Drag options to blanks, or click blank then click option'
A/
B/home
C/index.html
D/main
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/home' instead of '/' for the root route
Forgetting the leading slash
3fill in blank
hard

Fix the error in the code to run the Flask app only when the script is executed directly.

Flask
if __name__ == [1]:
    app.run(debug=True)
Drag options to blanks, or click blank then click option'
A'__main__'
B'run'
C'app'
D'main'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'main' without underscores
Using 'app' or 'run' instead of '__main__'
4fill in blank
hard

Fill both blanks to access the HTTP method and return it in the response.

Flask
from flask import request

@app.route('/method', methods=['GET', 'POST'])
def method():
    method_used = request.[1]
    return f'Method used: [2]'
Drag options to blanks, or click blank then click option'
Amethod
Bmethod_used
Cmethod()
Dmethod_used()
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.method() as if it were a function
Returning request.method directly without storing
5fill in blank
hard

Fill all three blanks to extract a URL parameter and return a greeting.

Flask
@app.route('/hello/<[1]>')
def hello([2]):
    return f'Hello, [3]!'
Drag options to blanks, or click blank then click option'
Aname
Busername
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching parameter name and function argument
Using different variable names in the return string