0
0
Djangoframework~10 mins

Messages framework for flash messages 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 import the Django messages module.

Django
from django.contrib import [1]
Drag options to blanks, or click blank then click option'
Asessions
Badmin
Cauth
Dmessages
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'sessions' instead of 'messages'.
Trying to import 'flash' which is not a Django module.
2fill in blank
medium

Complete the code to add an info message in a Django view.

Django
messages.[1](request, 'Profile updated successfully!')
Drag options to blanks, or click blank then click option'
Adebug
Binfo
Cerror
Dsuccess
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'success' when the message is informational.
Using 'debug' which is not usually shown to users.
3fill in blank
hard

Fix the error in the template code to correctly display messages.

Django
{% if messages %}
  <ul>
  {% for message in [1] %}
    <li>{{ message }}</li>
  {% endfor %}
  </ul>
{% endif %}
Drag options to blanks, or click blank then click option'
Amessages
Bflash_messages
Cmsgs
Dmessage_list
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not passed in the context.
Forgetting to enable messages context processor.
4fill in blank
hard

Fill both blanks to add a warning message and import the correct level constant.

Django
from django.contrib.messages import [1]
messages.add_message(request, [2], 'Your session will expire soon.')
Drag options to blanks, or click blank then click option'
AWARNING
BERROR
CINFO
DSUCCESS
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a different level constant than used in add_message.
Using string literals instead of constants.
5fill in blank
hard

Fill all three blanks to create a success message with extra tags in a Django view.

Django
messages.add_message(request, [1], 'Data saved!', extra_tags=[2], fail_silently=[3])
Drag options to blanks, or click blank then click option'
Amessages.SUCCESS
B'highlight'
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'SUCCESS' instead of the constant.
Passing fail_silently as a string instead of a boolean.