'Embed Python in an HTML page

I'm trying to look for a way to embed Python code inside an HTML page.

I'm NOT talking about using Python as the back-end with tools like Django or Flask. I would like to implement a very very basic console on my webpage so that I can show off Python scripts running, not just pure code. The user would then be able to modify the python, then re-run it to see changes.

Suppose I'm making a python programming tutorial website, and I want the user to see that print("hello world"), when run, output "hello world".

Is there a way to achieve this?



Solution 1:[1]

I found that it's called a "Fiddle". That was the keyword to know for further google searches. I've tried most of them, they don't work, except for one, https://ideone.com/ They also allow to easily embed it in your own web page, which is exactly what I needed.

Solution 2:[2]

Python inside HTML Allows you to be able to embed Python within HTML documents, similiar to mod_Python or PHP.By taking advantage of both the Module: digiweb and a slightly modified version of PythonInsideHTML.zip from the BSD licensed project Karrigell Python web server to make it a stand alone library. It is possible to run embed Python within a HTML document that can be executed at run time. Download Here

Solution 3:[3]

The best way is to set up a web framework that uses Python. Some good choices are Django, TurboGears, and Pyramid. While it is possible to do pure Python CGI or as an ISAPI extension, you don't really gain much from that approach, and a web framework is bound to be more efficient, understandable, and helpful.

Furthermore, web frameworks come with a philosophy and contain a lot of careful thought and best practices that you can learn from while you're working. Below are some web site links -

https://docs.pylonsproject.org/en/latest/

http://turbogears.org/

https://www.djangoproject.com/

Solution 4:[4]

Try trinket.io! Trinket lets you embed, share and save python code for free!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Omar Moharam
Solution 3 Akash
Solution 4 ab-tho