0
0
Flaskframework~10 mins

WSGI concept overview in Flask - Interactive Code Practice

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

Complete the code to define a simple WSGI application function.

Flask
def application(environ, [1]):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return [b'Hello World']
Drag options to blanks, or click blank then click option'
Astart_response
Bsend_response
Crequest
Dresponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect argument names like 'response' or 'request' instead of 'start_response'.
Forgetting to include the 'start_response' argument.
2fill in blank
medium

Complete the code to call the start_response function with status and headers.

Flask
def application(environ, start_response):
    [1]('200 OK', [('Content-Type', 'text/html')])
    return [b'<h1>Welcome</h1>']
Drag options to blanks, or click blank then click option'
Asend_response
Bbegin_response
Cstart_response
Dresponse_start
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like 'send_response' or 'begin_response'.
Not calling the function before returning the body.
3fill in blank
hard

Fix the error in the WSGI application to return the response body correctly as bytes.

Flask
def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return [[1]]
Drag options to blanks, or click blank then click option'
A'Hello World'
Bb'Hello World'
Cbytearray('Hello World')
Dstr('Hello World')
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a normal string instead of bytes.
Returning a non-iterable instead of a list or iterable.
4fill in blank
hard

Fill both blanks to create a Flask app and run it with debug mode on.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello Flask!'

if __name__ == '__main__':
    app.[1](debug=[2])
Drag options to blanks, or click blank then click option'
Arun
Bstart
Cexecute
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like 'start' or 'execute'.
Setting debug to a string instead of a boolean.
5fill in blank
hard

Fill all three blanks to create a WSGI middleware that prints a message before calling the app.

Flask
def simple_middleware(app):
    def middleware(environ, start_response):
        print([1])
        return app([2], [3])
    return middleware
Drag options to blanks, or click blank then click option'
A'Middleware active'
Benviron
Cstart_response
D'Starting app'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing wrong arguments to the app call.
Printing a variable instead of a string message.