0
0
Djangoframework~10 mins

Built-in middleware overview in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add Django's built-in middleware for security.

Django
MIDDLEWARE = [
    '[1]',
]
Drag options to blanks, or click blank then click option'
Adjango.middleware.security.SecurityMiddleware
Bdjango.middleware.common.CommonMiddleware
Cdjango.middleware.csrf.CsrfViewMiddleware
Ddjango.middleware.clickjacking.XFrameOptionsMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing middleware that handles other concerns like CSRF or clickjacking.
2fill in blank
medium

Complete the code to include middleware that manages sessions.

Django
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    '[1]',
]
Drag options to blanks, or click blank then click option'
Adjango.contrib.sessions.middleware.SessionMiddleware
Bdjango.middleware.csrf.CsrfViewMiddleware
Cdjango.middleware.clickjacking.XFrameOptionsMiddleware
Ddjango.middleware.common.CommonMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing session middleware with CSRF or common middleware.
3fill in blank
hard

Fix the error in the middleware list by adding the correct middleware for CSRF protection.

Django
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    '[1]',
]
Drag options to blanks, or click blank then click option'
Adjango.middleware.clickjacking.XFrameOptionsMiddleware
Bdjango.middleware.csrf.CsrfViewMiddleware
Cdjango.middleware.common.CommonMiddleware
Ddjango.middleware.locale.LocaleMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Using middleware for clickjacking or locale instead of CSRF.
4fill in blank
hard

Fill both blanks to add middleware for common HTTP features and clickjacking protection.

Django
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    '[1]',
    '[2]',
]
Drag options to blanks, or click blank then click option'
Adjango.middleware.common.CommonMiddleware
Bdjango.middleware.locale.LocaleMiddleware
Cdjango.middleware.clickjacking.XFrameOptionsMiddleware
Ddjango.middleware.gzip.GZipMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing locale or gzip middleware instead of common or clickjacking.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering middleware names that contain 'Security' and converting them to uppercase.

Django
security_middleware = {name[1]: name[2] for name in MIDDLEWARE if 'Security' [3] name}
Drag options to blanks, or click blank then click option'
A.lower()
B.upper()
Cin
Dnot in
Attempts:
3 left
💡 Hint
Common Mistakes
Using not in instead of in, or wrong string methods.