0
0
Flaskframework~10 mins

Custom status codes 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 return a custom status code 202 in a Flask route.

Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/')
def home():
    return jsonify(message='Accepted'), [1]
Drag options to blanks, or click blank then click option'
A200
B500
C404
D202
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 instead of 202
Using 404 which means Not Found
2fill in blank
medium

Complete the code to define a Flask response with a custom status code 418 (I'm a teapot).

Flask
from flask import Flask, Response
app = Flask(__name__)

@app.route('/teapot')
def teapot():
    return Response('I am a teapot', status=[1])
Drag options to blanks, or click blank then click option'
A418
B404
C200
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 instead of 418
Using 404 which means Not Found
3fill in blank
hard

Fix the error in the code to correctly return a JSON response with custom status code 429 (Too Many Requests).

Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/limit')
def limit():
    return jsonify(error='Too many requests'), [1]
Drag options to blanks, or click blank then click option'
A200
B429
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 instead of 429
Using 404 which means Not Found
4fill in blank
hard

Fill both blanks to create a Flask route that returns a JSON message with status code 451 (Unavailable For Legal Reasons).

Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/legal')
def legal():
    return jsonify([1]='Unavailable for legal reasons'), [2]
Drag options to blanks, or click blank then click option'
Amessage
Berror
C451
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' key instead of 'message'
Using 404 instead of 451
5fill in blank
hard

Fill all three blanks to return a Flask JSON response with a custom status code 207 (Multi-Status) and a custom key.

Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/multi')
def multi():
    return jsonify([1]=[2]), [3]
Drag options to blanks, or click blank then click option'
Astatus
B'multi-status'
C207
D'error'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'error' key instead of 'status'
Using 200 instead of 207