Problem with embeding python code in html?
NOT SURE ABOUT THIS: I think we cannot embed python code in html like we do with PHP, JSP
I have a piece of code I am trying to tamper with.
PAGE = urllib.unquote_plus("%3C%21doctype+html+public+%22-%2F%2FW3C%2FDTD+HTML+4.01%2F%2FEN%22+%22http ........
When I view source in the 开发者_开发知识库html file, I can see it being neatly displayed. But I am having a very hard time trying to figure out the %22 3C
What is happening? How to convert a sample code written neatly that python can understand.
You can use a template engine like Jinja2, Django's Template Engine or Mako Templates.
One way would be using <py-script> tag:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hello World!</title>
<!-- linking to PyScript assets -->
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<!-- Put Python code inside the the <py-script> tag -->
<py-script>
print("Hello World!")
input("Enter your name:")
</py-script>
</body>
</html>
Learn more about this at the PyScript site.
精彩评论