The albatross.apacheapp module contains a Request class to allow you to deploy your application using mod_python 4.2.
In the following example, we change the popview application from CGI to mod_python. The complete sample program is contained in the samples/popview5 directory. Use the install.py script to install the sample.
cd samples/popview5 python install.py
The new popview.py mainline follows.
from albatross import ModularSessionApp, SessionAppContext from albatross.apacheapp import Request import popviewlib class AppContext(SessionAppContext): def open_mbox(self): if hasattr(self.locals, 'mbox'): return self.locals.mbox = popviewlib.Mbox(self.locals.username, self.locals.passwd) def read_msg(self): if hasattr(self.locals, 'msg'): return self.locals.msg = self.locals.mbox[int(self.locals.msgnum) - 1] self.locals.msg.read_body() class App(ModularSessionApp): def __init__(self): ModularSessionApp.__init__(self, base_url='popview.py', module_path='-=-install_dir-=-', template_path='-=-install_dir-=-', start_page='login', secret='-=-secret-=-', session_appid='popview5') def create_context(self): return AppContext(self) app = App() def handler(req): return app.run(Request(req))
The handler() function is called by mod_python when a browser request is received that must be handled by the program.
You also need to create a .htaccess file to tell Apache to run the application using mod_python.
DirectoryIndex popview.py SetHandler python-program PythonHandler popview
Assuming you install the popview sample below the /var/www directory you will need configure Apache settings for the /var/www/alsamp directory:
<Directory /var/www/alsamp/> AllowOverride FileInfo Indexes Order allow,deny Allow from all </Directory>