Jorey Bump
list at joreybump.com
Thu Nov 9 09:09:50 EST 2006
Néstor Chacón Manzano wrote: > Hello, i' am newer in mod_python. > I try to probe this example: > <html> > <head> > <title>Prueba mod_python</title> > </head> > <body> > <form method='POST' action='python/getMonth'> > <p> > <hr> > <br /> > Selecciona el mes: <br /> > <select name='month'> > <option value='1'>Enero</option> > <option value='2'>Febrero</option> > <option value='3'>Marzo</option> > (...) > </select> > </p> > <br /> > <input type='submit' value="Muestra el mes"> > </form> > </body> > </html> > > In /var/www/python/ i have the script getMonth.py > > import calendar > from mod_python import apache > def getMonth(req,month): > req.write(calendar.month(2006,int(month),2,3)) > > My /etc/apache/apache2.conf have this entry: > > <Directory /var/www/python> > SetHandler mod_python > PythonHandler mod_python.publisher > PythonDebug On > </Directory> > > And the permisions of the files and directory are ugo+rx but when i probe this i get > > "The requested URL /python/GetMonth.py was not found on this server." > > Anyone idea? This is the default behaviour of Publisher. Modules are *not* publishable objects, only certain types of objects within them may be published. Objects that are published: =========================== Strings: hello = "Hello, Bruce!" Lists and tuples: order = ['spam', 'spam', 'spam', 'spam', 'eggs', 'spam'] Dictionaries: color = {'Lance': 'blue', 'Galahad': 'yellow', 'Robin': None} Instances (publishable attributes & methods): instance = MyClass Functions (only the output): def hello(req): return "Hello, Bruce!" Objects that are not published: =============================== Objects named with leading underscore: _secret = "BIGsecret" Classes: class MyClass: def __init__(self): self.attribute = "I can be published when I'm an instance." def function(self): return "Ocarina" Objects within a function: def hello(req): name = "Michael Baldwin" return "Hello, Bruce!" Imported modules and their objects (put the data into a publishable object first): import os The module itself: test.py This list is not exhaustive, I'm sure I've missed some objects. Publisher will produce a variety of errors or unusable output, depending on the object. Unfortunately, one of these is the somewhat misleading "not found" error when attempting to access the published module itself. Note that you generally do not need to import apache or use req.write in you Publisher modules. Simply return a string: import calendar def getMonth(req,month): return calendar.month(2006,int(month),2,3) And access it at: http://host/python/GetMonth/GetMonth
|