2

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.

0

2 Answers 2

3

You can use a template engine like Jinja2, Django's Template Engine or Mako Templates.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't like embedding python code in html, but I think it's the best answer to the question ;-)
I need to add just one like like this <img src=".com/tw.png "/> Do I need to use Django for this. Should I resort to decrypting the %3FC%2 etc ? Is there any software which will automatically do the conversion?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.