tags:

views:

206

answers:

3

this is a complete n00b question and i understand i may get voted down for asking this but i am totally confused over python's html integration. as i understand one way to integrate python with html code is by using mod_python. now, is there any other way or method that is more effective for using python with html?

please advise me on this as i am new to learning python and could use some help. some pointers to code samples would be highly appreciated.

thanks a lot.

EDIT: also what i would like to know is, how does PyHP and mod_python compare with regards to each other. i mean how are they different? and Django? what is Django all about?

+1  A: 

You can read a tutorial on how to use Python in the web.

http://docs.python.org/howto/webservers.html

In few words, mod_python keeps python interpreter in memory ready to execute python scripts, which is faster than launching it every time. It doesn't let you integrate python in html like PHP. For this you need to use a special application, like PyHP (http://www.pyhp.org) or another (there are several of them). Read Python tutorial and documentation pages, there's plenty of info and links to many template and html-embedding engines.

Such engines as PyHP require some overhead to run. Without them, your python application must output HTTP response headers and the page as strings. Mod_wsgi and fastcgi facilitate this process. The page I linked in the beginning gives a good overview on that.

Also you may try Tornado, a python web server, if you don't need to stick to Apache.

culebrón
i would rather stick to apache for now. thanks for your post. also what i would like to know is, how does PyHP and mod_python compare with regards to each other. i mean how are they different? and Django? what is Django all about?
amit
If you're sticking with Apache, I think you should probably look into mod_wsgi (http://www.modwsgi.org/) instead of mod_python.
Will McCutchen
mod_python is a barebone python interpreter. With it you need to output headers and other staff on your own or use a CGI library. PyHP has some classes in it's package, but also constraints you in some aspects: like in PHP, you can't throw a header in the middle of a page.Django is a framework. It's a python package (a set of modules wihh some classes and functions) which facilitates a lot of operations like page generation, db querying. It's better to read their docs, since I'm not an expert on Django. http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
culebrón
The mod_python package provides a PSP handler which allows mixing of Python code and HTML, so statement that mod_python doesn't allow this is wrong.
Graham Dumpleton
+3  A: 

I would suggest you to start with web.py

Tzury Bar Yochay
Seconded. `web.py` has a very low barrier to entry, so you can get up and running fast.
Will McCutchen
+1  A: 

The standard way for Python web apps to talk to a webserver is WSGI. Also check out WebOb.

But for a complete noob I'd start with a complete web-framework (in which case you typically can ignore the links above). Django or Grok are both full-stack framworks that are easy to use and learn. Django is more popular, but Grok is built on 13 years of Web application publishing experience, and is seriously cool. The difference is a matter of taste.

If you want something more minimalistic, the worlds your oyster, there are an infinite amount of web frameworks for Python, from BFG to Turbogears.

Lennart Regebro
thank you so much for your reply. highly appreciate it.
amit