Re: [Zope] Problems with External Script
At 12:58 PM 1/31/02 -0500, you wrote:
You use the RESPONSE object. That is, def ....(REQUEST, RESPONSE): .... location=... RESPONSE.redirect(location)
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=%(p..." % 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).
See http://www.zope.org/Members/michel/ZB/AppendixB.dtml for other things in repsonse.
This, unfortunately, had but 4 words on the subject, if I found the correct reference. Any more ideas? TIA, BenO
[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
On Thu, Jan 31, 2002 at 04:37:05PM -0500, Thomas B. Passin 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()
(snip)
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.
Actually, that part *is* proper python. $ python Python 2.1.2 (#1, Jan 18 2002, 18:05:45) [GCC 2.95.4 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information.
foo=1 bar = 2 "foo is %(foo)d, and bar is %(bar)d" % vars() 'foo is 1, and bar is 2' "foo is %(foo)d, and bar is %(bar)d" % locals() 'foo is 1, and bar is 2'
See for more info: http://www.python.org/doc/current/lib/typesseq-strings.html Anyway, as for the other attempts:
# location=RESPONSE.redirect("%(redir)s\n % locals()")
Close, but no cigar. First of all, you just want to call RESPONSE.redirect(). You don't want to store the return value. Secondly, the string interpolation has the quotes in the wrong place. should look like this: "%(redir)s\n" % locals()
# location-RESPONSE.redirect("http://thewebsons.com")
You're subracting the result of RESPONSE.redirect() from location. Definitely not what you want!
# location=redirect("http://thewebsons.com")
You're getting colder, you have to give a namespace to find the redirect method in. It lives in the RESPONSE object.
location: redirect("http://thewebsons.com")
Colons have a limited number of meanings in python, and that's not one of them. :) I get the feeling you don't really grok python. I suggest spending a little time with one of the tutorials. For instance: http://www.python.org/doc/current/tut/tut.html It's a great little language, and once you get the hang of it, Zope will open for you like an oyster with a great big shiny pearl inside (no pun intended).
All of those options (including the ones commented out) return a bad server request (Apache error #400).
I guess you're running behind Apache and it's helpfully hiding your traceback errors? That's not so helpful. Here's how to do a redirect. You don't use a return value from the redirect method; you just call it as the last step in your script or external method. RESPONSE.redirect("http://www.someplace.com") or REQUEST.RESPONSE.redirect("http://www.someplace.com") I've also seen it like this in the CMF sources, not sure why they write it this way, but it does the same thing. REQUEST['RESPONSE'].redirect("http://www.someplace.com") -- paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com
[Paul Winkler]
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.
Actually, that part *is* proper python.
Ah, the new syntax - I was thinking Python 1.5.2, as in pre-Zope 2.4. Tom P
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.
Actually, that part *is* proper python.
Ah, the new syntax - I was thinking Python 1.5.2, as in pre-Zope 2.4.
It works in python 1.5.2 too. print "%(foo)s" % {'foo': 'yo'} Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 10 http://nuxeo.com mailto:fg@nuxeo.com
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 )
participants (4)
-
Ben Ocean -
Florent Guillaume -
Paul Winkler -
Thomas B. Passin