advice needed for simple python web app

Michele Simionato michele.simionato at gmail.com
Fri Feb 4 00:44:55 EST 2005


Dan Perl:
> The application is just something I'm playing with to learn a little
bit on
> web apps.  It uses an HTML form to send an email.  The form takes
inputs
> like the From:, To: and Subject: fields and a text field.

It is difficult to beat CGI + CGIHTTPServer for conceptual simplificity
and easy of use: however, Quixote comes close and it has a *much*
better support for forms. Here is an
example from the minidemo in the distribution, so you have an idea of
how the code looks
like:

> from quixote.publish import Publisher
> from quixote.directory import Directory

> class RootDirectory(Directory):

>    _q_exports = ['', 'hello']

>    def _q_index(self):
>        return '''<html>
>                    <body>Welcome to the Quixote demo.  Here is a
>                    <a href="hello">link</a>.
>                    </body>
>                  </html>
>                '''

>    def hello(self):
>        return '<html><body>Hello world!</body></html>'


> def create_publisher():
>    return Publisher(RootDirectory(),
>                     display_exceptions='plain')


> if __name__ == '__main__':
>    from quixote.server.simple_server import run
>    print 'creating demo listening on http://localhost:8080/'
>    run(create_publisher, host='localhost', port=8080)

The exported methods of your directory class corresponds to Web pages;
_q_index
returns the main page, hello an hello word page. This works out of the
box with
no configuration at all, you don't need to create a cgi-bin directory,
nothing.
It is trivial to replace simple_server with a more serious server
(twisted_server,
scgi_server, etc. )

Notice: this example works in Quixote 2.0 which is currently in alpha.
Don't let
the "alpha" scares you: that means that the documentation is still a
bit rough and
few things are not fully settled down, but the framework is very much
usable.


                  Michele Simionato




More information about the Python-list mailing list