Recall & Review
beginner
What is the purpose of Django's Messages framework?
It allows you to store one-time notifications (flash messages) that can be displayed to users after a page reload or redirect.
Click to reveal answer
beginner
How do you add a message in a Django view?
Use the messages module, for example:
messages.success(request, 'Your profile was updated.').Click to reveal answer
intermediate
Name the default message levels provided by Django's Messages framework.
DEBUG, INFO, SUCCESS, WARNING, ERROR.
Click to reveal answer
beginner
How do you display messages in a Django template?
Use a loop over
messages context variable, for example:<br>{% raw %}{% if messages %}
{% for message in messages %}
<div class="{{ message.tags }}">{{ message }}</div>
{% endfor %}
{% endif %}{% endraw %}Click to reveal answer
intermediate
What middleware must be enabled for Django's Messages framework to work?
The
django.contrib.messages.middleware.MessageMiddleware must be included in the MIDDLEWARE setting.Click to reveal answer
Which function adds a success message in Django?
✗ Incorrect
The success() function adds a success-level flash message.
Where do you typically display flash messages in Django?
✗ Incorrect
Messages are displayed in templates by looping over the messages context variable.
Which middleware is required for Django messages to work?
✗ Incorrect
MessageMiddleware enables the messages framework to store and retrieve messages.
What happens to messages after they are displayed once?
✗ Incorrect
Messages are one-time notifications and are removed after being displayed.
Which message level is NOT part of Django's default levels?
✗ Incorrect
CRITICAL is not a default message level in Django's messages framework.
Explain how to add and display a flash message in Django using the Messages framework.
Think about the flow from view to template and middleware role.
You got /4 concepts.
List and describe the default message levels in Django's Messages framework.
Levels indicate message importance and style.
You got /5 concepts.