Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that you can have PHP -code inside HTML -file. I would like to know how you can do the same with Python.

How can you run Python inside a HTML document?

share|improve this question
up vote 3 down vote accepted

Look at django templating engine for example. django

share|improve this answer
I need to make my SQL queries by myself. I am afraid that I am not allowed to use Django. – Masi Jul 26 '09 at 18:30
You can still write your own queries with Django... Although I'll admit that defeats the purpose of using it. – Sasha Chedygov Jul 26 '09 at 18:50


Cheetah is a Python-powered template engine and code generator. It may be used as a standalone utility or combined with other tools. Cheetah has many potential uses, but web developers looking for a viable alternative to ASP, JSP, PHP and PSP are expected to be its principle user group.

share|improve this answer
@Charles: Cheetah sounds promising. I need to create my SQL queries by myself. Does Cheetah allow me to create my own SQL queries? – Masi Jul 26 '09 at 18:31

You will need something like mod_python for apache, or play with cgi.

It really depends on your web server

share|improve this answer
There are HTTP servers that are written in plain python. AFAIR python standard library includes one. There's no need to run apache for smale-scale deployments. – Tadeusz A. Kadłubowski Jul 26 '09 at 17:34
That's why I said it really depends on the web server :) – Yoann Le Touche Jul 26 '09 at 17:45

Use Mako or Jinja2. Both are very fast, and best at doing their job. You should not create SQL queries in your template, but in your controller logic. Later, pass variables/functions to a template and output them.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .