How can I run a Python script in HTML?

You are able to run a Python file using HTML using PHP.

Add a PHP file as index.php:

<html>
<head>
<title>Run my Python files</title>
<?PHP
echo shell_exec("python test.py 'parameter1'");
?>
</head>

Passing the parameter to Python

Create a Python file as test.py:

import sys
input=sys.argv[1]
print(input)

Print the parameter passed by PHP.

Leave a Comment