The Codeanaught
The Codeanaught

Reputation: 25

Can run Python code on a HTML page? How?

I have created a really cool Python program that I want all of my friends to try out. I really want to put the running code onto a website so people can try it all around the world. Is it possible to run Python code on a HTML page? If so, how?

Upvotes: 1

Views: 679

Answers (2)

therealrootuser
therealrootuser

Reputation: 10904

In answer to your question: Yes, this is possible.

If you merely want to share your code with your friends, and allow them to try it out (even without them having Python installed), in browser, then there are a number of tools that you can use.

For example, with https://trinket.io/ , you can embed a snippet of python code in an HTML webpage or share it via a link.

Update:

Another alternative online python site is http://repl.it/. Repl.it has compiled the CPython interpreter into Javascript, using an LLVM -> Javascript compiler. It is opensource, so you could even self-host if you wanted. Caveat: Some of the libraries still have bugs in them.

Upvotes: 3

tripleee
tripleee

Reputation: 189387

The simple pedestrian solution is to create a WSGI wrapper. You can configure your web server to accept input through a form (typically) and feed that to your Python program as input, then display the program's output as the response to the form submission. Thus your program runs on the server -- which needs to have the required services and resources -- but the user interaction happens simply using the client's web browser.

There are more-complex interaction models but this is how the entire web 1.0 was set up and is quick and easy to get going. (The spec back then was the similar platform-independent CGI API.)

Upvotes: 2

Related Questions