0
0
Flaskframework~10 mins

CORS configuration with Flask-CORS - 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 Flask-CORS extension.

Flask
from flask_cors import [1]
Drag options to blanks, or click blank then click option'
ACrossOrigin
BCors
CCORS
DCorsConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like CrossOrigin or CorsConfig.
2fill in blank
medium

Complete the code to initialize Flask-CORS for the Flask app.

Flask
app = Flask(__name__)
[1](app)
Drag options to blanks, or click blank then click option'
ACrossOrigin
BCORS
CFlaskCORS
Dcors_init
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a non-existent function like cors_init or FlaskCORS.
3fill in blank
hard

Fix the error in the code to allow CORS only for the origin 'http://example.com'.

Flask
CORS(app, resources={r"/*": {"origins": [1])
Drag options to blanks, or click blank then click option'
A'*'
Bhttp://example.com
C'http://example.com'
D['http://example.com']
Attempts:
3 left
💡 Hint
Common Mistakes
Using a plain string without list when a list is expected.
Using '*' which allows all origins.
4fill in blank
hard

Fill both blanks to configure CORS to allow only GET and POST methods from any origin.

Flask
CORS(app, resources={r"/*": {"origins": [1], "methods": [2])
Drag options to blanks, or click blank then click option'
A'*'
B['GET', 'POST']
C['PUT', 'DELETE']
D'GET, POST'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string with comma-separated methods instead of a list.
Restricting origins incorrectly.
5fill in blank
hard

Fill all three blanks to configure CORS with Flask app to allow origins 'http://site1.com' and 'http://site2.com', allow credentials, and only allow PUT method.

Flask
CORS(app, resources={r"/*": {"origins": [1], "supports_credentials": [2], "methods": [3])
Drag options to blanks, or click blank then click option'
A['http://site1.com', 'http://site2.com']
BTrue
C['PUT']
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of list for origins or methods.
Setting supports_credentials to string instead of boolean.