Software Solutions Company

Django Messages

Jan. 8, 2023
Author: Asif Shahzad | Full Stack Web Developer


Here I will show the procedure to display message when form is submited. After 5 second the message will disappear. Lets start!

1. Add in Setting.py

INSTALLED_APPS = [
    
    'django.contrib.messages',
   
]

For bootstrap message formates add this code in setting.py

from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
        messages.DEBUG: 'alert-secondary',
        messages.INFO: 'alert-info',
        messages.SUCCESS: 'alert-success',
        messages.WARNING: 'alert-warning',
        messages.ERROR: 'alert-danger',
}

This will show colouful alerts

2. Set up message template

{% for message in messages %}
<div class="container-fluid">
  <div id ="alert" class="alert {{ message.tags }} alert-dismissible" role="alert" >
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">×</span>
    </button>
    {{ message }}
  </div>
</div>
{% endfor %}


<script type="text/javascript">
    setTimeout(function () {

        // Closing the alert
        $('#alert').alert('close');
    }, 5000);
</script>

Here at the at the bottom, scripts hide the message after 5 seconds.

3. Include Message Template

Include Message Template in Django Form where required at top or bottom.

{% include 'main/messages.html' %}

4. In views.py add success and error

if form.is_valid():
            form.save()
            messages.success(request, 'Contact request submitted successfully.')
            
        else:
            messages.error(request, 'Invalid form submission.')
            messages.error(request, form.errors)

 

That's it.

Check the alerts.

Please share this page to friends.

Asif Shahzad | Full Stack Web Developer

Welcome to our Software Solutions Company, where we excel in transforming ideas into tangible realities. We have expertise in developing online management systems, website designing & development, software solutions, mobile app development, e-commerce solutions and graphic designing. We provide 24/7 services.

Latest Comments

Software Solutions Company

pHqghUme

Oct 29, 2024

@@BM7cw

Software Solutions Company

pHqghUme

Oct 29, 2024

����%2527%2522\'\"

Software Solutions Company

pHqghUme

Oct 29, 2024

'"

Software Solutions Company

pHqghUme

Oct 29, 2024

'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

Software Solutions Company

pHqghUme

Oct 29, 2024

*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

Software Solutions Company

pHqghUme

Oct 29, 2024

uuYKsvSU')) OR 680=(SELECT 680 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

BSXJfK0n') OR 344=(SELECT 344 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

NBtxntD5' OR 791=(SELECT 791 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

-1)) OR 800=(SELECT 800 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

-1) OR 394=(SELECT 394 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 87=(SELECT 87 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

Rf7XqJQc'; waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1); waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1; waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

Software Solutions Company

pHqghUme

Oct 29, 2024

0"XOR( *if(now()=sysdate(),sleep(15),0))XOR"Z

Software Solutions Company

pHqghUme

Oct 29, 2024

0'XOR( *if(now()=sysdate(),sleep(15),0))XOR'Z

Software Solutions Company

pHqghUme

Oct 29, 2024

*if(now()=sysdate(),sleep(15),0)

Software Solutions Company

pHqghUme

Oct 29, 2024

-1" OR 3+809-809-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1" OR 2+809-809-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 3+304-304-1=0+0+0+1 or 'hPsDNif6'='

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 2+304-304-1=0+0+0+1 or 'hPsDNif6'='

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 3+748-748-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 2+748-748-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 3+298-298-1=0+0+0+1

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 2+298-298-1=0+0+0+1

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 3+26-26-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 2+26-26-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

T7oyjT17

Software Solutions Company

pHqghUme

Oct 29, 2024

@@Qp2A0

Software Solutions Company

pHqghUme

Oct 29, 2024

����%2527%2522\'\"

Software Solutions Company

pHqghUme

Oct 29, 2024

'"

Software Solutions Company

pHqghUme

Oct 29, 2024

'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

Software Solutions Company

pHqghUme

Oct 29, 2024

*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

Software Solutions Company

pHqghUme

Oct 29, 2024

wzBP5rcj')) OR 252=(SELECT 252 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

NQG8XIon') OR 824=(SELECT 824 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

iX0mExB4' OR 444=(SELECT 444 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

-1)) OR 620=(SELECT 620 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

-1) OR 984=(SELECT 984 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 171=(SELECT 171 FROM PG_SLEEP(15))--

Software Solutions Company

pHqghUme

Oct 29, 2024

h1GzYrm8'; waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1); waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1; waitfor delay '0:0:15' --

Software Solutions Company

pHqghUme

Oct 29, 2024

(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

Software Solutions Company

pHqghUme

Oct 29, 2024

0"XOR( *if(now()=sysdate(),sleep(15),0))XOR"Z

Software Solutions Company

pHqghUme

Oct 29, 2024

0'XOR( *if(now()=sysdate(),sleep(15),0))XOR'Z

Software Solutions Company

pHqghUme

Oct 29, 2024

*if(now()=sysdate(),sleep(15),0)

Software Solutions Company

pHqghUme

Oct 29, 2024

-1" OR 3+193-193-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1" OR 2+193-193-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 3+76-76-1=0+0+0+1 or 'DswJUGhx'='

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 2+76-76-1=0+0+0+1 or 'DswJUGhx'='

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 3+851-851-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1' OR 2+851-851-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 3+649-649-1=0+0+0+1

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 2+649-649-1=0+0+0+1

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 3+212-212-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

-1 OR 2+212-212-1=0+0+0+1 --

Software Solutions Company

pHqghUme

Oct 29, 2024

exNDgWpE

Popular Posts






Call To Action

Do you Need a website?

Order Now