# message

অনেক সময় পোস্ট সেভ করার সময় সাকসেস এরর মেসেজ শো করানোর দরকার পরে এজন্য আমরা নিচের পদ্ধতি অবলম্বন করবো।

views.py

```python
from django.contrib import messages


                form.save()
                messages.success(request, "Success")
                
                messages.error(request, "Error message goes here.")
```

html

```html
{% if messages %}
    <div class="alert alert-dismissible">
        {% for message in messages %}
            <div {% if message.tags == 'success' %}class="alert alert-success"{% endif %} {% if message.tags == 'error' %}class="alert alert-danger"{% endif %}>
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                {{ message }}
            </div>
        {% endfor %}
    </div>
{% endif %}
```

এখানে আমরা বুটস্ট্র্যাপ এর ফরমেট ব্যবহার করেছি ইচ্ছা করলে যেকোন ফরমেট ব্যবহার করতে পারি।

<pre class="language-python"><code class="lang-python">&#x3C;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
&#x3C;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">&#x3C;/script>
&#x3C;script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">&#x3C;/script>

<strong>
</strong><strong>&#x3C;script>
</strong>           // Add this script to hide the alert messages after 5 seconds (5000 milliseconds)
           $(document).ready(function() {
            setTimeout(function() {
                $(".alert").alert('close');
            }, 5000); // 5000 milliseconds = 5 seconds
        });
&#x3C;/script>
</code></pre>
