[mod_python] PSP TypeError: cannot concatenate 'str' and 'instance' objects

Corey McGuire coreyfro at coreyfro.com
Fri Feb 17 04:39:23 EST 2006


Hello all,

I am learning python and PSP at the same time, which may be a bit of a
mistake, but I think I am doing well.

I am working on moving my PHP image gallery:
http://www.coreyfro.com/~coreyfro/gallery.php?gallery=b-man-2003

To python:
http://127.0.0.1/~coreyfro/gallery/gallery

This is really just an exercise, but it's kinda my own version of "Hello
World"

I am getting hung up ok this block of code:

cell_tmpl = psp.PSP(req, filename='cell.tmpl', vars = {'gallery': gallery,
'i': i, 'path': path, 'file': dirList[i], 'caption': caption})
body = body + cell_tmpl

Now, the kicker is "body = body + cell_tmpl"... If I leave it like that, I
get the following
http://127.0.0.1/~coreyfro/frozen/gallery1/gallery/?gallery=b-man-2003

If I try converting it to a string (like "body = body + str(cell_tmpl)")
something TOTALY wacky happens
http://127.0.0.1/~coreyfro/frozen/gallery2/gallery/?gallery=b-man-2003

It's outputting the HTML I am trying to append to body and NOT
concatinating it with body.

How do I put two and two together?

Here's the code in full

from mod_python import psp
import os

def report(req, title, caption, body):
    req.content_type            = 'text/html'
    gallery_tmpl                = psp.PSP(req, filename='gallery.tmpl')
    gallery_tmpl.run(vars       = { 'title': title, 'caption': caption,
'body': body  })

def index(req):
    title                       = "Coreyfro's Handy, Dandy, Super-duper,
Gallery Engine!"
    caption                     = "It's free, it's fast, it's incomplete!"
    body                        = "You are probably here by mistake<br>\
                                   Please feel free to be confused<br>\
                                   I know I am"
    report(req, title, caption, body)

def gallery(req, gallery='', columns=''):
    if columns:
        columns                 = int(columns)
    else:
        columns                 = 5

    if gallery:
        i                       = 0
        column                  = 1
        title                   = gallery
        caption                 = "Click on an image below to see it's
full sized version"
        path                    = "/home/coreyfro/public_html/gallery"
        dirList                 = os.listdir(path+"/"+gallery+"/ds")
        body                    = " " * 6 + "<table>\n" + " " * 8 + "<tr>\n"


        while i < len(dirList):
            if column < columns:
                column          = column + 1
            else:
                column          = 1
                body            = body + " " * 8 + "</tr>\n" + " " * 8 +
"<tr>\n"

            cell_tmpl           = psp.PSP(req, filename='cell.tmpl', vars
= {'gallery': gallery, 'i': i, 'path': path, 'file':
dirList[i], 'caption': caption})
            body                = body + cell_tmpl
            i                   = i + 1


        body                    = body + " " * 8 + "</tr>\n" + " " * 6 +
"</table>"
        report(req, title, caption, body)

    else:
        index(req)

def view(req, gallery, index):
    pass



More information about the Mod_python mailing list