Python web development, really

Remi Delon remi at cherrypy.org
Tue Jan 21 03:44:37 EST 2003


You might want to take a look at CherryPy (http://www.cherrypy.org)



> I would love to use Python instead of PHP for web development, but

> I have so far been confused by the options, or perhaps lack thereof,

> given my strict requirements. I would appreciate suggestions.

>

> I've looked at some Python options and have experience in quite a

> few platforms previously. I have always disliked PHP as a language,

> but at the same time have found it very accessible and useful.

>

> Possible solutions should do 99% of the following :

>

> * Run on the same hardware I use currently

It is 100% pure python so if python runs on your hardware, CherryPy will
too.

> * Be as fast or faster than Apache+PHP

> (I'm sorry to say Zope/Roxen are not)

> (This might mean it must use Apache)

>

> * Use a similar amount of memory

> (ie. not Java/.NET related)

CherryPy uses a "compile source files and generate a single executable for
your website" approach, so it doesn't get much faster than that. And the
executable is very lightweight (only a few MB for a simple website)

>

> * Provide a fairly equivalent framework w/ sessions, cookies, get, post

> (Described in http://www.boddie.org.uk/python/web_frameworks.html)

> (eg. I should not have to write code to parse query strings, etc.)

> (PHP is somewhat unique in the ways it can bring in post variables)

CherryPy is also somewhat unique in the way it handles get and post
variables :-) Each page request is converted into a regular function call
and get and post variables become the arguments of the call:

http://localhost/index?var1=val1&var2=val2

is converted to:

index(var1="val1", var2=val2)

so you'll just have to write a function like this:

def index(var1, var2):

And it doesn't matter if var1 and var2 are sent via a get or a post or if
they're a short string or a large file that's being uploaded: they're
handled the same way.

Cookies are also automatically parsed and put in a nice python map for you.

Sessions are not implemented yet.

> * Allow all errors to be caught and handled so users never see them

> (I currently send them to an email address)

> (Users are notified an error occurred and a developer contacted)

That's how I set up my websites too :-) It's a trivial thing to do with
CherryPy. Chapter 14.3.4 of the tutorial shows how to do this.

> * Allow sending of raw binary data, for restricted file downloading

> (eg. http://example.com/sendfile.php?id=A6DE12FAB3...etc)

> (This requires header manipulation, specifically the mime type)

> (That sort of thing should be part of the framework 3 bullets up)

I'm not sure what you mean by that but CherryPy allows you to work on the
response header and body before it is sent back to the browser. So what you
want is probably quite easy to do with CherryPy.

> * Allow SSL secured authorize.net credit card processing

> (I currently use PHP's libcurl+ssl module)

Yep, it supports SSL.

> * Allow similarly powerful regex capabilities

> (I currently use PHP's pcre module)

Well, you have access to all python modules from your code, so just pick the
one you want.

> * Big plus, but optional, auto prepend/append files

> (eg. Apache+PHP has .htaccess directives like this )

> ( php_value auto_prepend_file "_header.php" )

> ( php_value auto_append_file "_footer.php" )

> (granular down to the directory

You can do that with CherryPy AOP feature. Check out this HowTo:
http://www.cherrypy.org/static/html/howto/node12.html

> * Finally, very optional plus, global application scoped variables

> (PHP does NOT allow this, but I know why)

> (I do not want to hear why you think this is bad)

> (I know why it is good, I know why it can be bad)

Yep, you can use global variables.

> Some of these things likely already exist in Python itself and thus

> in anything which uses Python in a web development solution, but I am

> mentioning them explicitly because they are indeed still requirements.

> Plus explicit is better than implicit, as I'm sure everyone knows. ;-)

>

> Some links for future and others' reference :

> http://www.boddie.org.uk/python/web_frameworks.html

> http://www.boddie.org.uk/python/web_modules.html

> http://webware.sf.net/

> http://modsnake.sf.net/ (dead? that's too bad)

> http://www.apache.org/dist/httpd/modpython/

> http://pmz.sourceforge.net/

> http://www.mems-exchange.org/software/quixote/

> http://skunkweb.sourceforge.net/

>

> I hope I have not forgotten anything which will lead this thread to hell.

Well, you've forgotten CherryPy :-)

I suggest you take a look at http://www.cherrypy.org, check out the small
online demo and take a quick look at the documentation (HowTo and tutorial).

If it doesn't meet your requirements, please tell me what is missing/you
don't like so I can improve it :-)

Regards.

Remi.









More information about the Python-list mailing list