How to connect Python and HTML in a web application

xox

Joined Sep 8, 2017
936
Python is well supported but sometimes requires more configuration. Find out what kind of system your webhost uses. Linux-based Apache servers are usually smart enough to simply run a Python script as long as a hashbang is present and the file is marked executable. Modern webhosts often use somewhat more complex frameworks but again it's just a matter of setting things up correctly.
 

Ya’akov

Joined Jan 27, 2019
10,235
The easiest way to use Python for the web is through CGI (Common Gateways Interface). Although this is an older technique with some downsides, for your purpose it will probably be the easiest and fastest way to make things work.

The architecture of your programs and its naïve implementation are already far from optimal, so using CGI, which, under ordinary circumstances would probably be discouraged isn’t really a problem. While I am not a Python expert, I believe you will find a cgi.py library as part of the normal Python distribution. There are many tutorials on using CGI with Python.

CGI is simply a standardized way for http daemons and programs to establish IPC (Interprocess Communication). It uses the environment to pass variables to the program and STDIO for exchange. The variables you create in web forms are passed to the program with the names you choose, and the web server listens on STDIN for program output. Your program has to output the required headers for the HTTP protocol, and then any HTML you want sent to the browser.

Any competent tutorial will explain this, and it should be very easy to find one.

Good luck.
 
Top