Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run python script in HTML?

Tags:

Currently I'm having some python files which connects to sqlite database for user inputs and then performs some calculations which sets the output of the program. I'm new to python web programming and I want to know what is the best method to use python on web?

Ex: I want to run my python files when the user clicks a button on the web page. Is it possible?

I started with Django. But it needs some time for the learning. And I also saw something called CgiScripts. Which option should I use? Please advice.

like image 431
Ann Avatar asked Nov 28 '16 12:11

Ann


People also ask

How do I run a Python code from HTML?

To run, open command prompt to the New folder directory, type python server.py to run the script, then go to browser type localhost:5000 , then you will see button. You can click and route to destination script file you created. Hope this helpful.


1 Answers

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.

like image 90
Integraty_beast Avatar answered Sep 30 '22 04:09

Integraty_beast