mike watkins dot ca : Python Web Application Diary, Part Two

Python Web Application Diary, Part Two

In part one of this series, if you are following along, you installed some software components and hopefully have run one or more of the QP demo applications to prove that your configuration is working.

Where Code Lives

I presented in part one some of the choices I've made for my own system configuration as it pertains to file layouts and hierarchies.

QP is able to manage multiple applications, and requires only a little conformity to make that happen. Forget where applications should live? Issue the command qp -h.

Create a library

Throughout this series I'm going to be adding objects and UI elements to my own library, called Parlez (one of these days I'll release it) -- you probably want to create your own support library, maybe you'll call yours "snodgrass" - and add your objects to it. Ensure your library sits somewhere in your PYTHONPATH. Google is your friend. Mine looks something like this:

/www/lib/Parlez/
                bin/
                doc/
                lib/
                    test/
                    ui/
                        test/

/www/lib/parlez -> /www/lib/Parlez/lib

Create an application skeleton

Applications on the other hand are going to live under /var/qp_sites which I've symlinked from /www/qp_sites for my own personal configuration.

To create the application skeleton - something which you'll do frequently - I used to simply cp a template directory. Last night I created a short Python script to do this work for me. mkqpapp.py is available for download: http://mikewatkins.ca/software/files/qp/mkqpapp.py and running it is simple:

mkqpapp.py ~/qp_sites/blog 8011

Which should return with something like:

------------------------------------------------------------
blog application created in /usr/home/mw/qp_sites/blog

To start and stop blog issue the commands::

    qp blog start (or use qp -u blog)
    qp blog stop  (or use qp -d blog)

For more qp command line options::

    qp -h

To view the running application, visit::

    http://localhost:8011/

mkqpapp.py created the following under ~/qp_sites/blog/:

CHANGES
README
__init__.py
bin/
doc/
slash.qpy
test/
ui/
    test/
var/

So lets start it up:

qp -u blog

And visit the page at http://localhost:8011/ which shows:

It worked!

The blog application lives at /usr/home/mw/qp_sites/blog.

In Part Three of this series we'll actually get some code happening.