1

im working on a project where i have to create a gui for. The page that i'm working on has a form for user input that asks for a string. i want to take that input and send it to a python script that I have created for processing. The python script will then return a string of words to the javascript so that i can display it to the user in the webpage. Is there any way I can do so?

note: i am not an expert in programming hence please cut me some slack. it would be great if i could get a few examples as well.

lifeisaparty
  • 13
  • 1
  • 3

1 Answers1

2

You probably want to create and expose an HTTP endpoint using a Python web framework; the easiest choice would be Flask

This would require you to create a route/action view to handle POST requests using the Python script you created. You can then consume that HTTP endpoint using AJAX.

Another option would be to leverage the "serverless" infrastructure that Amazon Web Services provides; that way you could create an HTTP endpoint using Amazon API Gateway, and have that endpoint call an Amazon Lambda Python function, which would run your Python script and return the results. The advantage of this method is that is incredibly cheap and relatively easy to set up, especially if you only need to call that one Python script. Also, with this set up you wouldn't have to spin or maintain any web server yourself, since your Python script would be running directly on Amazon's servers.

Best of luck.