0

Tryna achieve sending notifications through Javascript logic instead of Django views, I want to replace alert() in this Javascript function with Django contrib messages(toasts). Something that would look like this in views messages.success(request, f"test successful") Is it possible to achieve the same thing with javascript?

js

function TestBtn(id) {
    alert("test successful");
}

html

<a onclick="TestBtn('btn');return false;"></a>
betty_
  • 61
  • 10
  • you need to pass variable to html via contex, and then put this variable in alert, here is how you can do it https://stackoverflow.com/questions/72215399/pass-django-variables-to-javascripts/72215521#72215521 – oruchkin Jun 12 '22 at 19:29
  • @oruchkin It doesn't look very clean, every time I would try to add an alert message, I would need to set up contexts, also it would display in alert format which I don't want – betty_ Jun 12 '22 at 19:54

0 Answers0