0
0
Flaskframework~10 mins

Why real-time 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]
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
Using render_template in place of Flask
Forgetting to import Flask
2fill in blank
medium

Complete the code to define a route that returns 'Hello World!'.

Flask
@app.route('/')
def home():
    return [1]
Drag options to blanks, or click blank then click option'
A'Hello World!'
Brender_template('index.html')
Credirect('/')
Djsonify(message='Hello World!')
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a function call instead of a string
Forgetting quotes around the string
Using redirect instead of returning text
3fill in blank
hard

Fix the error in the code to run the Flask app.

Flask
if __name__ == '__main__':
    app.[1](debug=True)
Drag options to blanks, or click blank then click option'
Aexecute
Bstart
Crun
Dlaunch
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() instead of run()
Calling execute() which does not exist
Forgetting parentheses after run
4fill in blank
hard

Fill both blanks to create a real-time message update using Flask-SocketIO.

Flask
from flask_socketio import SocketIO
socketio = SocketIO(app)

@socketio.[1]('[2]')
def handle_message(msg):
    print('Message:', msg)
Drag options to blanks, or click blank then click option'
Aemit
Bsend
Con
Dconnect
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'emit' as decorator instead of 'on'
Using 'connect' event instead of 'send'
Confusing 'send' with 'emit' in decorator
5fill in blank
hard

Fill all three blanks to emit a real-time event to clients.

Flask
from flask_socketio import emit

@app.route('/notify')
def notify():
    [1]('notification', [2]={'msg': 'Update!'}, [3]=True)
    return 'Notified'
Drag options to blanks, or click blank then click option'
Aemit
Bdata
Cbroadcast
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using send instead of emit
Passing message as a string instead of dictionary
Forgetting broadcast=True to notify all clients