Make a client POST request to Flask render_template endpoint Make a client POST request to Flask render_template endpoint flask flask

Make a client POST request to Flask render_template endpoint


For anyone who has such a use case too, ensure that you use a method post like below (put it inside the index.html in this case):

  <script>      $(document).ready(function() {          $("#clickMe").on('click', function() {              console.log('clicked, making a request')             post('/', {'key-1': 'val-1'});          })      }) function post(path, params, method='post') {     const form = document.createElement('form');     form.method = method;     form.action = path;     for (const key in params) {         if (params.hasOwnProperty(key)) {             const hiddenField = document.createElement('input');             hiddenField.type = 'hidden';             hiddenField.name = key;             hiddenField.value = params[key];             form.appendChild(hiddenField);         }     }     document.body.appendChild(form);     form.submit(); }  </script>

This creates a hidden form on the web page and then submits the form, from then onwards, flask processes everything properly.