[Tutor] mod_python and other web frameworks

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Thu Jan 26 14:37:08 CET 2006


Some others have already mentioned TurboGears, but since it sounds like
you want more control perhaps, I would recommend going with CherryPy
(http://www.cherrypy.org).  You basically write python code and then
expose it to the web (or intranet or whatever).

# simple example
import cherrypy
import time

class MySection(object):
    @cherrypy.expose
    def index(self):
        yield "<h1>Hello, world!</h1>"
        yield "<a href='time'>Check the time</a>"
# if you are using Python 2.3, you do the following to expose a method
#   index.exposed = True

    @cherrypy.expose
    def time(self):
        return "<p>The current time is %s</p>" % self.get_time()

# this method is not exposed and thus not accessible from the web
    def get_time(self):
        return time.ctime()

# mount the class at the server root
cherrypy.root = MySection()

cherrypy.server.start()
# end of example

You can then run that script and visit http://localhost:8080/.  That
will call the "index" method of the MySection object mounted at the
server root.  You can also visit http://localhost:8080/time.  However,
http://localhost:8080/get_time is _not_ available to the web, because it
is not "exposed".

Anyhow, CherryPy is very pythonic and flexible.  Use whatever DB you
want (or flat files or ...).  Use whatever templating language you want
(or just return html from your methods.

Anyhow, that's probably more info than you wanted.  Good luck!

Christian
http://www.dowski.com

ps And "as a beginner", I would _not_ start with something like
mod_python ;-)


-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Intercodes
Sent: Wednesday, January 25, 2006 12:59 PM
To: tutor at python.org
Subject: [Tutor] mod_python and other web frameworks

Hello everyone,

Disclaimer:  Beginner.

I have an idea of coding a web application and decided to do it entirely
with python (reddit style). I started looking for web programming in
python and somehow I saw mod_python first. Iam perusing the help
document now. 

Few minutes of browsing confused my mind entirely , since it seems there
are about 20 different web frameworks available for python. I am left
clueless as to pick which one. I have an soft side towards the one I
picked first. 

Considering yourself as a beginner to python  ,do you prefer mod_python
over all other framework?. Say if you want to create a blog , will
mod_python suffice? And is mod_python and cgi (the python lib)
different?


--
Intercodes




More information about the Tutor mailing list