0

I am trying to execute a .py file in html, but when i run the .py file it simply comes up as the source code.

Is it possible to import and execute a .py file from the html code. I have tried using <a href="___.py"></a> but when I click on the url it just brings up the source code of the .py file.

intboolstring
  • 6,519
  • 4
  • 28
  • 42
Leyton Taylor
  • 367
  • 2
  • 17
  • possible duplicate of [Call a python function within a html file](http://stackoverflow.com/questions/5615228/call-a-python-function-within-a-html-file) – Nate Barbettini Sep 19 '15 at 17:32

1 Answers1

2

It is not possible to directly execute a python file from HTML.

Here are some alternatives:

You could use a python-in-browser implementation like Skulpt (http://www.skulpt.org/)

You could use PHP. (If you're on ubuntu or similar, sudo apt-get install apache2 php)

<?php
echo shell_exec('python ___.py');
?>

You could try using a python-enabled web-server like Tornado (http://www.tornadoweb.org/en/stable/)

Sameer Puri
  • 936
  • 7
  • 20