0
0
Djangoframework~10 mins

Template configuration and directories 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 the templates directory path in Django settings.

Django
TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [[1]],
    'APP_DIRS': True,
}]
Drag options to blanks, or click blank then click option'
A'templates/'
B'media/'
C'static/'
D'scripts/'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'static/' instead of 'templates/'
Leaving DIRS empty when you have custom template folders
2fill in blank
medium

Complete the code to enable Django to find templates inside app directories.

Django
TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': [1],
}]
Drag options to blanks, or click blank then click option'
ATrue
B'enabled'
CFalse
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Setting APP_DIRS to False disables app template loading
Using string values instead of boolean
3fill in blank
hard

Fix the error in the template directory path to use an absolute path.

Django
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, [1])],
    'APP_DIRS': True,
}]
Drag options to blanks, or click blank then click option'
A'templates/'
B'/templates/'
C'./templates/'
D'templates'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/templates/' which creates an absolute path ignoring BASE_DIR
Using './templates/' which is relative and may cause errors
4fill in blank
hard

Fill both blanks to configure Django to load templates from a custom directory and app directories.

Django
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, [1])],
    'APP_DIRS': [2],
}]
Drag options to blanks, or click blank then click option'
A'custom_templates'
BFalse
CTrue
D'templates'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'templates' instead of the custom folder name
Setting APP_DIRS to False disables app template loading
5fill in blank
hard

Fill all three blanks to correctly set up template directories and enable app templates in Django settings.

Django
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, [1])],
    'APP_DIRS': [2],
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            [3]
        ],
    },
}]
Drag options to blanks, or click blank then click option'
A'templates'
BTrue
C'django.contrib.auth.context_processors.auth'
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the auth context processor
Setting APP_DIRS to False
Using incorrect directory names