Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
Passing a JS variable to Flask API URL

I made an API using Flask that has a url of this format

localhost:5000/data/?query=<Query Goes Here>

This API basically just returns a webapage with this small json:

{
"text" : "(Whatever we entered in the URL)"
}

I wanted to know how we can pass a Node.js variable to the URL ?

If it is not possible, how can I make an API in Python that

Takes input in JS -> Sends it to Python for Processing -> Sends output back to JS OR Displays a rendered page with that output

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I can answer you with this example.

Takes input in JS :

JS file :

$("#test_enable").on('click', function(e) {
  $this = $(this)
  var test_id = $("#test_id_generator").val(); # get a value from test_id_generator
        $.ajax({
          url: url,
          type: 'POST',
          data: {
            'test_id': test_id,
          },
          success: function (data) {
          location.reload(true)
        }
      });}

python file:

def product_register_disable(request):
    test_id = request.POST.get('test_id')

Sends output back to JS OR Displays a rendered page with that output

you can show the value using JINJA2 and python

python side

@routes.route('/showtime', methods=["GET", "POST"])
def showtime():
    return render_template('showtime.html', value = 'testtest')

HTML side

<!DOCTYPE html>
<html lang="en">
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> 
</script>
meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<body>
    <div>{{value}}</div>

I hope I help.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!