0

Hello I am trying to post information i get from a form to an API that submits it to the views.py file in Django. Can anyone tell me where i am going wrong. Below is my javascript code

        function functionsubmit(){
      const recipients = document.querySelector('#compose-recipients').value;
      const subject = document.querySelector('#compose-subject').value;
      const body = document.querySelector('#compose-body').value;
       fetch('/emails', {
      method: 'POST',
      body: JSON.stringify({
          recipients: recipients,
          subject: subject,
          body: body
      })
    })
    .then(response => response.json())
    .then(result => {
        console.log(result);
    });
}

The above code doesn't even print console.log(result); in the console. The name of the url i.e '/emails' is also the same inside django urls and the views.py file has no errors in it . Can some one tell me whats wrong with this.

You must log in to answer this question.

Browse other questions tagged .