[mod_python] Problems with PSP

Pedro Ferreira ilzogoiby at gmail.com
Sat Nov 5 09:50:03 EST 2005


Hello all.
I started using PSP some days ago, and decided to build some classes to 
simplify the creation of webforms. Unfortunately I'm having some 
problems with a "random" error. Sometimes the same page works ok, but 
sometimes it fails.
Since it works ok through the python interpreter (using the commented at 
the end of forms.py), i thought it might be a mod_python issue.
Any help would be appreciated.
Here is the code:

#------------
#index.psp
#............
<% page_title = "xpto" %>
<%@ include file="header.psp"%>
<div id="text">
<%
from forms import *

frm = Form('test','test.py')
fld = TextField('name','Full Name','Bill')
frm.addField(fld)
%>

<%=frm.getHTML()%>

</div>
<%@ include file="footer.psp"%>

#------------
#forms.py
#............

class Field:
    def __init__(self,name,label,defaultValue):
        self.name = name
        self.label = label
        self.defaultValue = defaultValue

class TextField(Field):        
    
    def __init__(self,name,label,defaultValue,size=0):
        Field.__init__(self,name,label,defaultValue)
        self.size = size

    def getHTML(self):
        ret = self.label+': <input name="'+self.name+'" value="'+self.defaultValue+'"';
        if (self.size != 0):
            ret += ' size="%d"' % (self.size);
        ret += ' />\n'
        return ret

class Form:
    def __init__(self,name,action):
        self.action = action
        self.name = name
        self.fields = []
    
    def addField(self, field):
        self.fields.append(field)
        
    def getHTML(self):
        ret = '<form name="'+self.name+'" method="POST" action="'+self.action+'">\n'
        for field in self.fields:
            ret += field.getHTML()
        ret += '</form>\n'
        return ret
        
#frm = Form('test','test.py')
#fld = TextField('name','Full Name','Bill',10)
#frm.addField(fld)

#print frm.getHTML()

.........................
SOMETIMES WORKS, SOMETIMES RESULTS IN THE FOLLOWING ERROR:

Mod_python error: "PythonHandler mod_python.psp"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 297, in handler
    p.run()

  File "/usr/lib/python2.4/site-packages/mod_python/psp.py", line 208, in run
    exec code in global_scope

  File "/home/mahound/public_html/santuario/index.psp", line 26, in ?

  File "/home/mahound/public_html/santuario/forms.py", line 32, in getHTML
    ret += field.getHTML()

TypeError: cannot concatenate 'str' and 'NoneType' objects


....................

Thanks in advance,

Pedro


More information about the Mod_python mailing list