Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Gunicorn's WSGI server to run a Flask app.
Flask
from flask import Flask app = Flask(__name__) if __name__ == '__main__': from [1] import WSGIApplication http_server = WSGIApplication('__main__:app') http_server.cfg.set('bind', '0.0.0.0:8000') http_server.run()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing from 'gunicorn' directly instead of the correct submodule.
Using 'gunicorn.http' which is unrelated to WSGI server.
Trying to import from 'gunicorn.workers' which is for worker classes.
✗ Incorrect
The correct import for Gunicorn's WSGI server in this context is from 'gunicorn.app.wsgiapp'.
2fill in blank
mediumComplete the command to start a Flask app with Gunicorn on port 5000.
Flask
gunicorn -b 0.0.0.0:5000 [1]:app
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' as the module name when it's usually the variable name.
Using 'server' which is not the module name.
Forgetting to specify the module before ':app'.
✗ Incorrect
The Gunicorn command requires the Python module name where the Flask app instance 'app' is defined. Commonly, this is 'wsgi'.
3fill in blank
hardFix the error in the Gunicorn command to run with 4 worker processes.
Flask
gunicorn -w [1] myapp:app Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using words like 'four' instead of the number 4.
Using invalid strings like 'worker4'.
Using spelled-out numbers causing syntax errors.
✗ Incorrect
The '-w' option expects a number for workers, so '4' is correct. Words like 'four' or 'two' cause errors.
4fill in blank
hardFill both blanks to create a Gunicorn command that binds to localhost on port 8080 and uses 2 workers.
Flask
gunicorn -w [2] -b 127.0.0.1:8080 [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping module and app names.
Using wrong number of workers.
Incorrect binding address format.
✗ Incorrect
The module and app instance is 'myapp:app' and the number of workers is '2'.
5fill in blank
hardFill all three blanks to create a Gunicorn command that runs 'server:app' with 3 workers and logs to 'gunicorn.log'.
Flask
gunicorn -w [2] --log-file [3] [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping module and app names.
Using wrong number of workers.
Forgetting to specify the log file.
✗ Incorrect
The correct module and app is 'server:app', workers count is '3', and log file is 'gunicorn.log'.