Python可以像PHP和JSP一样嵌入到HTML中吗?

时间:2022-11-12 13:44:23

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

有没有像使用PHP或JSP那样编写嵌入HTML的Python的方法?

5 个解决方案

#1


20  

Use a template engine, such as:

使用模板引擎,例如:

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

python wiki还有一篇关于这个主题的文章,还有更多的建议。

#2


6  

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.

有一些可用的python作为模板语言,但它很讨厌因为python对空白敏感,所以必须添加特殊的语法黑客。

#3


2  

Several templating engines support this in one way or another: Mako, Jinja, and Genshi are all popular choices.

一些模板引擎以这样或那样的方式支持它:Mako,Jinja和Genshi都是受欢迎的选择。

Different engines support different features of Python and may be better suited to your needs. Your best bet is to try them out and see what works.

不同的引擎支持Python的不同功能,可能更适合您的需求。你最好的选择是尝试一下,看看哪些有效。

#4


1  

Use Cheetah or another templating engine.

使用猎豹或其他模板引擎。

#5


0  

Yes, I recall there was a python ASP plugin from activestate that works this way.

是的,我记得有一个来自activestate的python ASP插件以这种方式工作。

#1


20  

Use a template engine, such as:

使用模板引擎,例如:

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

python wiki还有一篇关于这个主题的文章,还有更多的建议。

#2


6  

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.

有一些可用的python作为模板语言,但它很讨厌因为python对空白敏感,所以必须添加特殊的语法黑客。

#3


2  

Several templating engines support this in one way or another: Mako, Jinja, and Genshi are all popular choices.

一些模板引擎以这样或那样的方式支持它:Mako,Jinja和Genshi都是受欢迎的选择。

Different engines support different features of Python and may be better suited to your needs. Your best bet is to try them out and see what works.

不同的引擎支持Python的不同功能,可能更适合您的需求。你最好的选择是尝试一下,看看哪些有效。

#4


1  

Use Cheetah or another templating engine.

使用猎豹或其他模板引擎。

#5


0  

Yes, I recall there was a python ASP plugin from activestate that works this way.

是的,我记得有一个来自activestate的python ASP插件以这种方式工作。