I want the user to be sent to a particular URL after calling the product's manage_add method. How can I do that? The URL I want is REQUEST['URL3']. I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the RESPONSE doesn't seem to exist here. -- ................. paul winkler .................. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com
* Paul Winkler <slinkp23@yahoo.com> [001127 19:54]:
I want the user to be sent to a particular URL after calling the product's manage_add method. How can I do that? The URL I want is REQUEST['URL3'].
I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the RESPONSE doesn't seem to exist here.
sounds alright to me. are you calling it in quotes, e.g. <dtml-var "RESPONSE.redirect(REQUEST['URL3'])"> ? you shouldn't have to use the REQUEST to look up the variable, either: <dtml-var "RESPONSE.redirect(URL3)">
seb bacon wrote:
* Paul Winkler <slinkp23@yahoo.com> [001127 19:54]:
I want the user to be sent to a particular URL after calling the product's manage_add method. How can I do that? The URL I want is REQUEST['URL3'].
I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the RESPONSE doesn't seem to exist here.
sounds alright to me. are you calling it in quotes, e.g. <dtml-var "RESPONSE.redirect(REQUEST['URL3'])"> ?
you shouldn't have to use the REQUEST to look up the variable, either: <dtml-var "RESPONSE.redirect(URL3)">
Thanks for the reply. OK, I didn't phrase the question correctly. I think it boils down to this: If I have a string that represents a URL, can I define a method of my product (in python, not in DTML) that redirects the browser to that URL? More details: My product code is based on Boring (like most newbies I guess). But manage_addBoring() does not do quite what I want. It returns self.manage_main(self, REQUEST), so they end up at a long and ugly URL that isn't where I want them to be anyway. Example: the user is at: http://localhost.localdomain:8080/Members/bobby Bobby then clicks on a button I've provided that says "Add Test Product". That sends him to the add form I've created. When Bobby submits the request from this form, the product is added and he's sent to http://localhost.localdomain:8080/Members/bobby/manage_addProduct/MyProduct/... ...because manage_addMyProduct returns self.manage_main So I understand what's happening, but it's not what I want. I don't want to send him there, I want to send him back to http://localhost.localdomain:8080/Members/bobby So how can I do that from within the manage_addMyProduct method definition? The method gets a REQUEST argument, and I know that REQUEST['URL3'] is what I want because if I return that string, it prints the URL I want. I could do it by returning an HTML page with a redirect in the <head> but that seems like a horribly ugly solution. Looking through various Zope docs, I thought RESPONSE.redirect might work, but RESPONSE is not mentioned anywhere in Boring.py. Boring only uses REQUEST. -- ................. paul winkler .................. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com
Paul Winkler wrote:
seb bacon wrote:
* Paul Winkler <slinkp23@yahoo.com> [001127 19:54]:
I want the user to be sent to a particular URL after calling the product's manage_add method. How can I do that? The URL I want is REQUEST['URL3'].
I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the RESPONSE doesn't seem to exist here.
sounds alright to me. are you calling it in quotes, e.g. <dtml-var "RESPONSE.redirect(REQUEST['URL3'])"> ?
you shouldn't have to use the REQUEST to look up the variable, either: <dtml-var "RESPONSE.redirect(URL3)">
Thanks for the reply. OK, I didn't phrase the question correctly.
I think it boils down to this: If I have a string that represents a URL, can I define a method of my product (in python, not in DTML) that redirects the browser to that URL?
More details:
My product code is based on Boring (like most newbies I guess). But manage_addBoring() does not do quite what I want. It returns self.manage_main(self, REQUEST), so they end up at a long and ugly URL that isn't where I want them to be anyway.
Example: the user is at:
http://localhost.localdomain:8080/Members/bobby
Bobby then clicks on a button I've provided that says "Add Test Product". That sends him to the add form I've created. When Bobby submits the request from this form, the product is added and he's sent to
http://localhost.localdomain:8080/Members/bobby/manage_addProduct/MyProduct/...
...because manage_addMyProduct returns self.manage_main So I understand what's happening, but it's not what I want. I don't want to send him there, I want to send him back to
http://localhost.localdomain:8080/Members/bobby
So how can I do that from within the manage_addMyProduct method definition? The method gets a REQUEST argument, and I know that REQUEST['URL3'] is what I want because if I return that string, it prints the URL I want.
I could do it by returning an HTML page with a redirect in the <head> but that seems like a horribly ugly solution.
Looking through various Zope docs, I thought RESPONSE.redirect might work, but RESPONSE is not mentioned anywhere in Boring.py. Boring only uses REQUEST.
So pass it RESPONSE: def manage_addMyProduct(self, blah, blah, REQUEST=None, RESPONSE=None): ... The publisher will automaticaly pass you RESPONSE if you ask for it as a method argument. Now use RESPONSE.redirect. -Michel
Michel Pelletier wrote:
Paul Winkler wrote:
(snip)
Looking through various Zope docs, I thought RESPONSE.redirect might work, but RESPONSE is not mentioned anywhere in Boring.py. Boring only uses REQUEST.
So pass it RESPONSE:
def manage_addMyProduct(self, blah, blah, REQUEST=None, RESPONSE=None): ...
The publisher will automaticaly pass you RESPONSE if you ask for it as a method argument. Now use RESPONSE.redirect.
Aha, thanks. I didn't know that about the publisher. Now I'm afraid I'm too stupid to see how to use RESPONSE.redirect after reading the description in the Zope Book API appendix. My method now looks like this: def manage_addMyProduct(self, id, title='', REQUEST=None, RESPONSE=None): """Add a MyProduct instance to the folder.""" self._setObject(id, MyProduct(id, title)) if REQUEST is not None: whereto= REQUEST['URL3'] return RESPONSE.redirect(whereto, 0) That just prints the URL as a string. OK, so maybe I'm not supposed to use the return value? So I try it like this: def manage_addMyProduct(self, id, title='', REQUEST=None, RESPONSE=None): """Add a MyProduct instance to the folder.""" self._setObject(id, MyProduct(id, title)) if REQUEST is not None: whereto= REQUEST['URL3'] RESPONSE.redirect(whereto, 0) Now when I submit the form, I can wait for a result forever and not get anything. How am I *really* supposed to do it? -- ................. paul winkler .................. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com
OK, this seems to work. def manage_addMyProduct(self, id, title='', REQUEST=None, RESPONSE=None): self._setObject(id, MyProduct(id, title)) if REQUEST is not None: whereto= REQUEST['URL3'] RESPONSE.redirect(whereto, lock=0) -- ................. paul winkler .................. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com
You need to be careful when redirecting from an external Python wotsit. RESPONSE.redirect raises an exception which can make the transaction get rolled back. This seems not to happen when called from dtml but I've seen it happen from an external Python wotsit. Note: My use of wotsit above in no way has a bearing on the new name for the Python Methods/ZMethods/Script or whatever the hell they are called now. ;) Phil phil.harris@zope.co.uk ----- Original Message ----- From: "Paul Winkler" <slinkp23@yahoo.com> To: "Zope mailing list" <zope@zope.org> Sent: Monday, November 27, 2000 6:26 PM Subject: [Zope] newbie question: Redirect from Python? | I want the user to be sent to a particular URL after calling the | product's manage_add method. How can I do that? | The URL I want is REQUEST['URL3']. | | I've tried RESPONSE.redirect(REQUEST['URL3']) but that's not it - the | RESPONSE doesn't seem to exist here. | | | -- | ................. paul winkler .................. | slinkP arts: music, sound, illustration, design, etc. | web page: http://www.slinkp.com | A member of ARMS: http://www.reacharms.com | | _______________________________________________ | 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 )
Phil Harris wrote:
You need to be careful when redirecting from an external Python wotsit.
RESPONSE.redirect raises an exception which can make the transaction get rolled back.
This seems not to happen when called from dtml but I've seen it happen from an external Python wotsit.
Note:
My use of wotsit above in no way has a bearing on the new name for the Python Methods/ZMethods/Script or whatever the hell they are called now. ;)
Thanks for the warning. Does this only happen in certain circumstances? I'm not using an External Method or a Python Script or whatever those things are called now. I'm doing it in a Product. Does that matter? ................. paul winkler .................. slinkP arts: music, sound, illustration, design, etc. web page: http://www.slinkp.com A member of ARMS: http://www.reacharms.com
participants (4)
-
Michel Pelletier -
Paul Winkler -
Phil Harris -
seb bacon