0
0
Djangoframework~10 mins

Middleware ordering importance 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 = [
    '[1]',
    'django.middleware.common.CommonMiddleware',
]
Drag options to blanks, or click blank then click option'
Adjango.middleware.clickjacking.XFrameOptionsMiddleware
Bdjango.middleware.security.SecurityMiddleware
Cdjango.middleware.csrf.CsrfViewMiddleware
Ddjango.middleware.locale.LocaleMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Placing SecurityMiddleware too low in the list.
Confusing middleware classes with view functions.
2fill in blank
medium

Complete the code to ensure the CSRF middleware runs after the session middleware.

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.locale.LocaleMiddleware
Cdjango.middleware.common.CommonMiddleware
Ddjango.middleware.csrf.CsrfViewMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Placing CSRF middleware before session middleware causes errors.
Omitting CSRF middleware entirely.
3fill in blank
hard

Complete the code to ensure clickjacking protection works properly by placing it last.

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.locale.LocaleMiddleware
Ddjango.middleware.common.CommonMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Placing XFrameOptionsMiddleware too early.
Removing important middleware like SecurityMiddleware.
4fill in blank
hard

Fill both blanks to correctly order middleware for session and locale support.

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

Fill all three blanks to create a middleware list with security, session, and CSRF middleware in correct order.

Django
MIDDLEWARE = [
    '[1]',
    '[2]',
    '[3]',
    'django.middleware.common.CommonMiddleware',
]
Drag options to blanks, or click blank then click option'
Adjango.middleware.security.SecurityMiddleware
Bdjango.contrib.sessions.middleware.SessionMiddleware
Cdjango.middleware.csrf.CsrfViewMiddleware
Ddjango.middleware.locale.LocaleMiddleware
Attempts:
3 left
💡 Hint
Common Mistakes
Placing CSRF middleware before session middleware.
Putting security middleware too late.