combining mod_python handlers publisher and psp problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • exhuma.twn

    #1

    combining mod_python handlers publisher and psp problem

    Simple problem:

    When I define a funtion the way you would with the publisher handler
    (without using psp), all works as expected. However when I define a
    publisher-like function and instantiate a PSP object in it ( as
    suggested on
    Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology

    ) mod_python seems to fail to tell the browser which content-type the
    document has. The output is what I expect it to be, but instead of
    rendering the page I see the source code, so I suppose the browser sees
    it as "text/python" or "text/plain".

    I tried to do a

    print "Content-Type: text/html"
    print

    as first statement, but then it only outputs that as normal text too.

    Any ideas?

  • exhuma.twn

    #2
    Re: combining mod_python handlers publisher and psp problem

    exhuma.twn wrote:[color=blue]
    > Simple problem:
    >
    > When I define a funtion the way you would with the publisher handler
    > (without using psp), all works as expected. However when I define a
    > publisher-like function and instantiate a PSP object in it ( as
    > suggested on
    > http://www.onlamp.com/pub/a/python/2...ver_pages.html
    > ) mod_python seems to fail to tell the browser which content-type the
    > document has. The output is what I expect it to be, but instead of
    > rendering the page I see the source code, so I suppose the browser sees
    > it as "text/python" or "text/plain".
    >
    > I tried to do a
    >
    > print "Content-Type: text/html"
    > print
    >
    > as first statement, but then it only outputs that as normal text too.
    >
    > Any ideas?[/color]

    Update:
    I got it working. My old code was as follows:

    def index(req, name='John'):
    s = 'Hello, there!'
    if name:
    names = ['a', 'b', 'c']
    s = 'Hello, %s!' % name.capitalize ()
    tmpl = psp.PSP(req, filename='index .psp')
    tmpl.run(vars = { 'greet': s, 'names': names })
    return

    Now I did this:

    def index(req, name='John'):
    s = 'Hello, there!'
    if name:
    names = ['a', 'b', 'c']
    s = 'Hello, %s!' % name.capitalize ()
    tmpl = psp.PSP(req, filename='index .psp',
    vars = { 'greet': s, 'names': names })
    return tmpl

    So basically I assigned the variables on instantiation of the PSP
    object and returned the resulting reference. This is different to what
    is noted at onlamp.com

    Comment

    • grahamd@dscpl.com.au

      #3
      Re: combining mod_python handlers publisher and psp problem

      You could also have done:

      def index(req, name='John'):
      s = 'Hello, there!'
      if name:
      names = ['a', 'b', 'c']
      s = 'Hello, %s!' % name.capitalize ()
      tmpl = psp.PSP(req, filename='index .psp')
      req.content_typ e = 'text/html'
      tmpl.run(vars = { 'greet': s, 'names': names })
      return

      Try the mod_python mailing list if you want an explaination of why.

      Graham

      Comment

      • exhuma.twn

        #4
        Re: combining mod_python handlers publisher and psp problem


        grahamd@dscpl.c om.au wrote:[color=blue]
        > You could also have done:
        >
        > def index(req, name='John'):
        > s = 'Hello, there!'
        > if name:
        > names = ['a', 'b', 'c']
        > s = 'Hello, %s!' % name.capitalize ()
        > tmpl = psp.PSP(req, filename='index .psp')
        > req.content_typ e = 'text/html'
        > tmpl.run(vars = { 'greet': s, 'names': names })
        > return
        >
        > Try the mod_python mailing list if you want an explaination of why.
        >
        > Graham[/color]

        Thanks, that worked.

        Comment

        Working...