Complete the code to define a simple WSGI application function.
def application(environ, [1]): start_response('200 OK', [('Content-Type', 'text/plain')]) return [b'Hello World']
The WSGI application function takes two arguments: environ and start_response. The start_response callable is used to begin the HTTP response.
Complete the code to call the start_response function with status and headers.
def application(environ, start_response): [1]('200 OK', [('Content-Type', 'text/html')]) return [b'<h1>Welcome</h1>']
The start_response function is called with the HTTP status and headers to begin the response.
Fix the error in the WSGI application to return the response body correctly as bytes.
def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [[1]]
The WSGI application must return an iterable of byte strings. Using b'Hello World' ensures the response is bytes.
Fill both blanks to create a Flask app and run it with debug mode on.
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello Flask!' if __name__ == '__main__': app.[1](debug=[2])
To run a Flask app with debug mode, call app.run(debug=True).
Fill all three blanks to create a WSGI middleware that prints a message before calling the app.
def simple_middleware(app): def middleware(environ, start_response): print([1]) return app([2], [3]) return middleware
The middleware prints a message, then calls the wrapped app with environ and start_response.