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?


Look at django templating engine for example. django

  • I need to make my SQL queries by myself. I am afraid that I am not allowed to use Django. 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. 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.

  • @Charles: Cheetah sounds promising. I need to create my SQL queries by myself. Does Cheetah allow me to create my own SQL queries? 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

  • 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. Jul 26 '09 at 17:34
  • That's why I said it really depends on the web server :) 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.