24

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

1
  • You can with mod_python; but mod_wsgi + Django is a better way to go. Commented Feb 27, 2015 at 11:05

5 Answers 5

23

Use a template engine, such as:

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

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

1 Comment

I looked through cog and saw that it is mostly applicable to C++. How would you implement it in HTML???
7

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.

Comments

2

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

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.

Comments

1

Use Cheetah or another templating engine.

Comments

0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.