use toasts in django 1

use toasts in django

    {% if messages %}
        {% for message in messages %}
            {% if message.tags == 'success'%}
                
            {% elif message.tags == 'info' %}
                
            {% elif message.tags == 'warning' %}
                
            {% elif message.tags == 'error' %}
                
            {% endif %}
        {% endfor %}
    {% endif %}

Here is what the above code is Doing:
1. First, we’re importing the messages from the django.contrib.messages framework.
2. Next, we’re checking if there are any messages in the messages framework.
3. If there are messages, we’re looping through them and checking the tags.
4. If the tag is success, we’re calling the toastr.success() function and passing the message as the argument.
5. If the tag is info, we’re calling the toastr.info() function and passing the message as the argument.
6. If the tag is warning, we’re calling the toastr.warning() function and passing the message as the argument.
7. If the tag is error, we’re calling the toastr.error() function and passing the message as the argument.

Similar Posts