[Welcome] [TitleIndex] [WordIndex

Presumably you already have the MiniDemo working. To add another page to the root directory, add its name to the _q_exports list and a method with the same name that returns the contents of the page.

class RootDirectory(Directory):

    _q_exports = ['', 'hello', 'goodbye']

    # code for _q_index and hello omitted
    def goodbye(self):
        return '<html><body>Goodbye</body></html>'

By default, Quixote assumes the pages have a content type of text/html. You can change it by modifying the HTTPResponse object:

from quixote import get_response

class RootDirectory(Directory):

    _q_exports = ['', 'hello', 'plain']

    def plain(self):
        return "This is a plain text document."

You can create sub-directories by exporting Directory attributes. For example:

class SubDirectory(Directory):

    _q_exports = ['']

    def _q_index(self):
        return '<html><body>I'm a sub-directory.</body></html>'

class RootDirectory(Directory):

    _q_exports = ['', 'hello', 'subdir']


    subdir = SubDirectory()

Accessing http://localhost:8080/subdir/ should return "I'm a sub-directory".

If you would rather use CGI than a stand-alone server, change the last three lines of script to:

if __name__ == '__main__':
    from quixote.server.cgi_server import run

You probably also need to rename the script to have a .cgi extension and move it into your server's cgi-bin directory.

TODO: Add note about using mod_fcgid (it's much faster and easy to setup). Perhaps say something about how to use PTL and the form framework (even though they are completely optional).

At some point, you will probably want to structure your application as a Python package rather than a single script. The BigDemo works this way so you might want to look at how it works.

2010-09-22 22:14