[Django]-How to send alert message from HttpResponseRedirect django

3👍

In your template, you can do:

<script type="text/javascript">
 $(function(){
   {% if alert %}
      //whatever conditions and js code
      alert('{{alert}}');
   {% endif %}
 });
</script>

and in views, use redirect instead of HttpResponseRedirect

return redirect(reverse("/dashboard/all_users"), {"alert":r.content})

Leave a comment