[Welcome] [TitleIndex] [WordIndex


You want to get Quixote up and running quickly, so you can start coding. You already have an Apache + mod_python installation, so all you really need is the right lines to put in your httpd.conf file.


Note: This solution is written for Quixote 1. The same basic idea should work for Quixote 2 as well.

Let's say your application is called "myquixoteapp", and you want to access it via a URL that starts with /myq (e.g. http://localhost/myq/func/params). Add the following to your httpd.conf:

<Location /myq>                                                                                                                                                        
    SetHandler python-program                                                                                                                                          
    PythonHandler quixote.mod_python_handler                                                                                                                           
    PythonOption quixote-root-namespace myquixoteapp                                                                                                                   
    PythonInterpreter myquixoteapp                                                                                                                                     
    PythonDebug On                                                                                                                                                     

Now you need to make sure the "myquixoteapp" package can be found by Python. The simplest way to do that is to put it in your site-packages directory.


_q_exports = []                                                                                                                                                        
from myquixoteapp.pages import _q_index                                                                                                                                


def _q_index [html] (request):                                                                                                                                         
    <head><title>Hello from Quixote</title></head>                                                                                                                     
    <h1>Hello, world!</h1>                                                                                                                                             
    Hello from Quixote!                                                                                                                                                

Restart Apache (to pick up the new Location directive), then point your browser to http://localhost/myq and see the results for yourself.


One gotcha to watch out for: since mod_python gets loaded into the address space of each separate Apache process, you might experience weird results if you modify your source code and then hit the "Reload" button on your browser. You might end up talking to an Apache process that already imported the Quixote mod_python_handler module, and thus it will have the old copies of your HTML pages (or your Python modules) lying around. Or you might end up talking to a freshly-forked process, which will grab the new version of the page you modified. Even an apachectl graceful won't necessarily guarantee that all the old processes die; you'll need to do a full-fledged `apachectl restart` to make sure that your modifications get through to the browser.

CategoryCookbook CategoryQuixote1

2010-09-22 22:14