1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
1. In views.py, import messages module from django.contrib import messages 2. Paste the following code immediately below form.save() messages.success(request, 'Successfully Saved') 3. Paste the code in the template where you want to display the message {% if messages %} <ul class="messages"> {% for message in messages %} <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li> {% endfor %} </ul> {% endif %} 4. Style the message .success{ list-style: none; background-color: #2e6da4; color: white; box-shadow: 12px 12px 12px #e61c66; text-align: center; } |
原文:http://www.arbcoms.com/23-how-to-add-notification-in-django/