[Zope] Problems with External Script

Ben Ocean zope@thewebsons.com
Fri, 01 Feb 2002 06:32:18 -0800


Thank you! That worked!
BenO

At 04:37 PM 1/31/02 -0500, you wrote:
>[Ben Ocean]
>
> >
> > Okay, gotta be close by now :/
> > Here's my script:
> >
> > import string
> >
> > def myaffiliateprogram(REQUEST,RESPONSE):
> >   user_id, banner_id, page =
> > REQUEST['user_id'],REQUEST['banner_id'],REQUEST['page']
> >   redir =
> >
>"http://www.myaffiliateprogram.com/u/%(user_id)s/t.asp?id=%(banner_id)s&p=%(
>page)s"
> > % locals()
> > # location=RESPONSE.redirect("%(redir)s\n % locals()")
> > # location-RESPONSE.redirect("http://thewebsons.com")
> > # location=redirect("http://thewebsons.com")
> >   location: redirect("http://thewebsons.com")
> >
> > All of those options (including the ones commented out) return a bad
>server
> > request (Apache error #400).
> >
>
>This isn't proper python, so I don't see how it would have worked at all.
>If you want to interpolate variables into a string, you have to use "%s",
>not "%(something else)s".  If that's not what you are trying to do, the
>expression % locals() isn't valid.  Also, do you mean
>
>     location= redirect("http://thewebsons.com")
>
>?
>
>Remember, your external method has to ***return something*** to Zope - I
>don't think you want to be calling a redirect from this external method.
>
>You probably want to accomplish something like this:
>
>in Zope:
>
><dtml-call "RESPONSE.redirect(myaffilitateprogram(REQUEST))">
>
>In the external method, skipping the banner stuff:
>
>  def myaffiliateprogram(REQUEST):
>     # Do the banner stuff with the REQUEST
>     # Do whatever it takes to figure out where you want to go to...
>     # if that place is http://thewebsons.com, then end with:
>
>     location="http://thewebsons.com"
>     return location
>
>Assuming that RESPONSE.redirect() is the correct syntax (I've never used it
>myself), this will cause a redirect() method call on the RESPONSE object
>from within the dtml page, which would be what you want.  The value of the
>argument for the redirect will be whatever the external method returned.
>
>Generally you want your external methods to return something, which Zope
>then uses in some dtml to do something.
>
>Cheers,
>
>Tom P
>
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )