2.4 Testing

  1. Make some directory that would be visible on your web site, for example, htdocs/test.

  2. Add the following Apache directives, which can appear in either the main server configuration file, or .htaccess. If you are going to be using the .htaccess file, you will not need the <Directory> tag below, and you will need to make sure the AllowOverride directive applicable to this directory has at least FileInfo specified. (The default is None, which will not work.)

    <Directory /some/directory/htdocs/test> 
      AddHandler python-program .py
      PythonHandler mptest 
      PythonDebug On 
    </Directory>
    

    (Substitute /some/directory above for something applicable to your system, usually your Apache ServerRoot)

  3. At this time, if you made changes to the main configuration file, you will need to restart Apache in order for the changes to take effect.

  4. Edit mptest.py file in the htdocs/test directory so that is has the following lines (be careful when cutting and pasting from your browser, you may end up with incorrect indentation and a syntax error):

    from mod_python import apache
    
    def handler(req):
        req.send_http_header()
        req.write("Hello World!")
        return apache.OK
    

  5. Point your browser to the URL referring to the mptest.py; you should see "Hello World!". If you didn't - refer to the troubleshooting section next.

  6. If everything worked well, move on to Chapter 3, Tutorial.