How to run python script in HTML?

How to run python script in HTML?

You can able to run a python file using html using php

write 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 as test.py:

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

print the parameter passed by PHP.

It probably would depend on what you want to do. I personally use CGI and it might be simpler if your inputs from the web page are simple, and it takes less time to learn. Here are some resources for it:

However you may still have to do some configuring to allow it to run the program instead of displaying it.

Heres a tutorial on that: http://httpd.apache.org/docs/current/howto/cgi.html

How to run python script in HTML?

If your web server is apache you can use the http://modpython.org/ module in order to run your python CGI scripts.

For nginx you can use http://modwsgi.readthedocs.io/en/develop/

Leave a Reply

Your email address will not be published. Required fields are marked *