I have been using Django message framework to show the success or failure message in my application. But I want the UI to be good so I found out that toastr is a good way to display messages to the user. But I am not sure how to use it. Please guide me through this.
The function below saves the user to the database and when the user info is save a message is displayed:
def addSubscriber(request):
template = 'addSubscriber.html'
if request.method == 'POST':
form = addSubsForm(request.POST)
if form.is_valid():
f = form.save(commit=False)
f.save()
messages.success(request, "The Subscriber has been successfully added")
return redirect('report')
else:
messages.error(request, "Sorry the data has not been entered to the database")
else:
form = addSubsForm()
return render(request, template, {'form': form})
The following template shows the display of the message:
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}