Complete the code to import the Django messages module.
from django.contrib import [1]
The Django messages framework is accessed via django.contrib.messages. Importing messages allows you to use flash messages in views.
Complete the code to add an info message in a Django view.
messages.[1](request, 'Profile updated successfully!')
The info method adds an informational flash message. Other methods like success or error add different message levels.
Fix the error in the template code to correctly display messages.
{% if messages %}
<ul>
{% for message in [1] %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}In Django templates, the variable messages is used to loop over flash messages. Using any other name will cause an error or no messages shown.
Fill both blanks to add a warning message and import the correct level constant.
from django.contrib.messages import [1] messages.add_message(request, [2], 'Your session will expire soon.')
The WARNING constant is imported and used as the message level to add a warning flash message.
Fill all three blanks to create a success message with extra tags in a Django view.
messages.add_message(request, [1], 'Data saved!', extra_tags=[2], fail_silently=[3])
The messages.SUCCESS constant sets the message level. The extra_tags adds CSS classes, and fail_silently=False ensures errors raise exceptions.