May 2, 2022

Message and Allert With Django and Boostrap

Sometime you need to send an allert/message from your Django project to the user, like a popup or a gui message for an user interaction (“Sent the mail”, “Done the task”, …) and you want to make it with style (Boostrap in this case).

So this is my code.

Check if in the settings you have:

  • django.contrib.messages is in INSTALLED_APPS
  • django.contrib.sessions.middleware.SessionMiddleware and django.contrib.messages.middleware.MessageMiddleware are in MIDDLEWARE
  • The context_processors option of the DjangoTemplates backend defined in your TEMPLATES setting contains django.contrib.messages.context_processors.messages

This is the standard configuration for django messages and we need to add some config for Boostrap.