Recall & Review
beginner
What is a custom template filter in Django?
A custom template filter is a user-defined function that processes data in Django templates to change how values are displayed. It lets you create your own way to modify or format data inside templates.
Click to reveal answer
beginner
How do you register a custom template filter in Django?
You create a Python function and register it with Django's template library using the @register.filter decorator inside a file in the 'templatetags' folder. This makes the filter available in templates.
Click to reveal answer
intermediate
Where should you place your custom template filter code in a Django project?
Inside a 'templatetags' folder within a Django app. This folder must contain an __init__.py file to be recognized as a module.
Click to reveal answer
beginner
What is the purpose of the @register.filter decorator in Django custom filters?
It tells Django that the function below it is a template filter and makes it available to use inside templates.
Click to reveal answer
intermediate
Can custom template filters accept arguments? How?
Yes, custom filters can accept extra arguments by defining them in the function parameters after the value. You can pass these arguments in the template using a colon, like {{ value|filtername:arg }}.
Click to reveal answer
Where do you put custom template filters in a Django app?
✗ Incorrect
Custom template filters must be placed inside a 'templatetags' folder within a Django app, which must have an __init__.py file.
How do you make Django recognize a function as a template filter?
✗ Incorrect
The @register.filter decorator registers the function as a template filter in Django.
What does a custom template filter do?
✗ Incorrect
Custom template filters change how data is displayed in templates by modifying or formatting it.
How do you pass an argument to a custom template filter in a template?
✗ Incorrect
Arguments are passed to filters in templates using a colon, like {{ value|filtername:argument }}.
What file must exist inside the 'templatetags' folder for Django to recognize it?
✗ Incorrect
The __init__.py file makes the 'templatetags' folder a Python module so Django can load filters from it.
Explain how to create and use a custom template filter in Django from start to finish.
Think about folder structure, function, registration, loading, and usage.
You got /5 concepts.
Describe how to pass an argument to a custom template filter and how to handle it in the filter function.
Focus on function parameters and template syntax.
You got /3 concepts.