0
0
Djangoframework~10 mins

Middleware configuration 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 a middleware class to the Django settings.

Django
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    [1],
    'django.middleware.common.CommonMiddleware',
]
Drag options to blanks, or click blank then click option'
A'django.middleware.csrf.CsrfViewMiddleware'
B'django.middleware.clickjacking.XFrameOptionsMiddleware'
C'django.middleware.locale.LocaleMiddleware'
D'django.contrib.sessions.middleware.SessionMiddleware'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing middleware unrelated to session management.
Forgetting to include quotes around the middleware path.
2fill in blank
medium

Complete the code to add a custom middleware class path to the settings.

Django
MIDDLEWARE += [
    [1]
]
Drag options to blanks, or click blank then click option'
A'myapp.middleware.CustomMiddleware'
B'django.middleware.common.CommonMiddleware'
C'django.middleware.security.SecurityMiddleware'
D'django.middleware.csrf.CsrfViewMiddleware'
Attempts:
3 left
💡 Hint
Common Mistakes
Using built-in middleware instead of custom middleware path.
Omitting quotes around the middleware path.
3fill in blank
hard

Fix the error in the middleware list by completing the missing middleware.

Django
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.[1]',
    'django.middleware.common.CommonMiddleware',
]
Drag options to blanks, or click blank then click option'
ASessionMiddleware
BCsrfViewMiddleware
CLocaleMiddleware
DAuthenticationMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing session middleware with CSRF middleware.
Using middleware from the wrong Django module.
4fill in blank
hard

Fill both blanks to correctly configure middleware that handles authentication and CSRF protection.

Django
MIDDLEWARE = [
    [1],
    [2],
]
Drag options to blanks, or click blank then click option'
A'django.contrib.auth.middleware.AuthenticationMiddleware'
B'django.middleware.security.SecurityMiddleware'
C'django.middleware.csrf.CsrfViewMiddleware'
D'django.middleware.common.CommonMiddleware'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up security middleware with authentication middleware.
Omitting CSRF middleware which is important for form security.
5fill in blank
hard

Fill all three blanks to create a middleware list that includes security, session, and clickjacking protection.

Django
MIDDLEWARE = [
    [1],
    [2],
    [3],
]
Drag options to blanks, or click blank then click option'
A'django.middleware.security.SecurityMiddleware'
B'django.contrib.sessions.middleware.SessionMiddleware'
C'django.middleware.clickjacking.XFrameOptionsMiddleware'
D'django.middleware.common.CommonMiddleware'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to include session middleware.
Mixing up middleware order which can affect behavior.