jab
jab

Reputation: 5823

Taking an HTML form, passing information to Python Script

I'm a novice at web programming, and right now, I am trying to write a web interface to python python program.

I'm wanting to fill in a simple form, hit submit, pass data to a python script, have the script pass data back to the same HTML file and display this data on the HTML file.

So, which way do I go about doing this? I have the HTML file done and I have my python program done, but no communication between the two. Should I use post to python using cgi or should I call javascript to create a json object and then pass that in to python and have python pass another json object back to me?

Upvotes: 0

Views: 445

Answers (1)

Quentin
Quentin

Reputation: 944306

Should I use post to python

Use a form. It is simple and works. The choice between post and get depends on what you are doing with the data.

using cgi

The client submits to the server using HTTP.

How the server communicates with the Python then depends on a number of factors. CGI has the benefits of being simple and easy to set up (but it doesn't scale well).

or should I call javascript to create a json object and then pass that in to python and have python pass another json object back to me?

You could layer something like that on top of the form solution. (Remember to be progressive and unobtrusive). There isn't much benefit in using JSON for the input if you have a flat data structure though. I wouldn't bother with it unless you were dealing with complex data structures on the client.

Upvotes: 1

Related Questions