0

I need to create an API end point like :

@app.route('/user/<username>')
def user(username)
  -- do something with the username

in the index.html the code for input box is :

<input type="username" name="user_name" id="uname" placeholder="Input your  name">

Pls advise how I can pass this input as the 'username' variable?

nhrcpt
  • 862
  • 3
  • 21
  • 51

1 Answers1

0

You need to get the value after user submit. Using javascript to get that value and make the request to Flask server.

function makeRequest(event) {
  fetch('/user/'+ event.target.value)
    .then(function(response) {
      console.log(response)
    })
}
....
<input type="text" id="foo" value="bar" onkeyup="makeRequest(this)" />
Raja Simon
  • 10,126
  • 5
  • 43
  • 74