You need to flip that around, you want to run server-side python code that renders your sexy HTML5 GUI. There are many Python frameworks that are suitable to this, including web2py, django, and my personal favorite flask.
Any of these frameworks will let your python code run, then render the HTML with python variables/functions available by using a templating engine (for example Flask uses Jinja template). Tutorials are readily available for all of these python libraries, but if you want to take a look at Flask, I can recommend Miguel Grinberg's excellent tutorial series.
Answer from binaryatrocity on Stack OverflowYou are able to run a Python file using HTML using PHP.
Add 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 file 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:
- cgi — Common Gateway Interface support
- Python - CGI Programming
However, you may still have to do some configuring to allow it to run the program instead of displaying it.
Here's a tutorial on that: Apache Tutorial: Dynamic Content with CGI
Can you use a HTML5 library in a python program?
How do people mix Python / other code in with HTML / CSS / JS?
Is it possible to use Python script on a html page?
How can I include python script in a HTML file? - Stack Overflow
Never really used HTML, only know its used for sites and is a mark-up language.
I want to use a HTML5 library to make charts in a python program (python program is a backtester for trading strategies).
Charting library in HTML5:
https://www.tradingview.com/lightweight-charts/
https://github.com/tradingview/lightweight-charts
If someone could point me in the right direction or give a top-down overview/summary/explanation would be very helpful, thank you.
I'm sort of new to programming, I'm intermediate in Python, and I know some HTML, barely any CSS and some Javascript. I'm just wondering how people use Python code with them?
Something like this, if you want to create an html, not necessarily display it:
html_file = open('namehere.html','w')
a = ['f','d','s','a']
x = -1
scope = vars()
data = ''
for i in a: #TIP: use a generator
scope['x']+=1
data += a[x]
data += '\n'
html_file.write(data)
html_file.close()
There's now a solution to this, the solution is PyScript. This is a python framework that enables you to embed python scripts in HTML. Check out the sample code below.
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<py-script>
print("Hello World")
</py-script>
</body>
</html>