0
0
Flaskframework~10 mins

Response object creation 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 import the Response class from Flask.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
AResponse
Brender_template
CFlask
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'request' instead of 'Response'.
Importing 'Flask' which is the app class, not the response.
2fill in blank
medium

Complete the code to create a Response object with the text 'Hello World'.

Flask
resp = Response([1])
Drag options to blanks, or click blank then click option'
AHello World
B'Hello World'
Cresponse
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the string.
Passing variables that are undefined.
3fill in blank
hard

Fix the error in the code to set the status code of the Response to 404.

Flask
resp = Response('Not Found')
resp.[1] = 404
Drag options to blanks, or click blank then click option'
Acode
Bstatus
Cstatus_code
DstatusText
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'status_code'.
Using 'code' which is not a valid attribute.
4fill in blank
hard

Fill both blanks to create a Response with JSON content and set the content type header.

Flask
resp = Response([1])
resp.headers['[2]'] = 'application/json'
Drag options to blanks, or click blank then click option'
Ajson.dumps({'key': 'value'})
Bjsonify({'key': 'value'})
CContent-Type
DAccept
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'jsonify' which returns a Response, not a string.
Setting header key to 'Accept' instead of 'Content-Type'.
5fill in blank
hard

Fill all three blanks to create a Response with custom text, status 201, and a custom header.

Flask
resp = Response([1], status=[2])
resp.headers['[3]'] = 'CustomValue'
Drag options to blanks, or click blank then click option'
A'Created successfully'
B201
CX-Custom-Header
DContent-Length
Attempts:
3 left
💡 Hint
Common Mistakes
Using numeric status as string.
Using standard headers instead of custom header name.