Django. Only change in bank via html

1

I've been developing in Django for a short time, I have a nice image on my site, when I click on it I would like to only change a field in the database without reloading or resending the page and stay in the same place.

I have a question about how to call a Python function directly in html or via javascript what is the best way to do this?

I searched in several places and did not find an answer, the only way I found was passing via url, but then I would have to render the page again?

I'm using django 2.1 and python 3.7 Thanks in advance for the help.

    
asked by anonymous 29.08.2018 / 14:40

1 answer

1

When you want to send something backend (your system) without having to reload the page, then you will need to use an AJAX call using javascript. In this post and you will see a way to do this. But it would look something like this:

  <script>
    $("#image").onclick(function () {

      $.ajax({
        url: '/url/da/view/que/vai/processar/essa/chamada/',
        data: {
          'id': algumacoisa.id,
        },
        dataType: 'json',
        success: function (data) {
            alert("A user with this username already exists.");
        }
      });

    });
  </script>
    
31.08.2018 / 00:02