Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Python be embedded in HTML like PHP and JSP?

Tags:

Is there a way of writing Python embedded in HTML like I do with PHP or JSP?

like image 642
Zerho Avatar asked Mar 02 '11 14:03

Zerho


People also ask

Can Python be embedded in HTML?

It is possible to run embed Python within a HTML document that can be executed at run time.

Does Python work with HTML?

You can use python in your HTML code. You don't need to know javascript. PyScript is not just HTML only, it is more powerful, because of the rich and accessible ecosystem of Python libraries.


2 Answers

Use a template engine, such as:

  • Jinja2 (based on Django's templating)
  • mako
  • Cog
  • Cheetah

The python wiki also has an article on this topic, with many more suggestions.

like image 101
Dolph Avatar answered Oct 31 '22 09:10

Dolph


There is... But you're highly suggested to use a templating engine, or some other means of separating the presentation from the business layer.

There are some available that use python as the templating language, but it's nasty because python is sensitive to whitespace, so special syntax hacks have to be added.

like image 30
Arafangion Avatar answered Oct 31 '22 08:10

Arafangion