quick search:
 

Pass URL parameters from a Script (Python) to a DTML Method

Submitted by: ewalstad
Last Edited: 2005-09-17

Category: Python(Script)

Average rating is: 5.0 out of 5 (1 ratings)

Description:
Redirect your user to a DTML method from a Script (Python) with URL parameters

Source (Text):
from Products.PythonScripts.standard import url_quote

parameter_to_pass = url_quote("Jane Johnson")
destination = 'MyTargetDTMLMethod'

context.REQUEST.RESPONSE.redirect(destination + "?Name=" + parameter_to_pass)

# In the DTML Method "MyTargetDTMLMethod" you can display the
# Passed-in parameter like so:
<dtml-var standard_html_header>
The Last Name is: <dtml-var expr="REQUEST.form['Name']" newline_to_br>
<dtml-var standard_html_footer>

Explanation:
I needed this functionality to direct the user to an error page if an error was encountered in my Script (Python).

The tricky part for me was figuring out how to URL quote my parameter string.
I found out how by reading the recipe:
"STX in Python Scripts" by aemadrid
http://www.zopelabs.com/cookbook/996779620


Comments:

what about that? :-) by amine - 2004-10-14
from Products.PythonScripts.standard import url_quote
context.REQUEST.RESPONSE.redirect(any_destination + "?Name=ewalstad@ewalstad.com")

try this script, and...
what a surprise!!! :-)


completion to my previous post by amine - 2004-10-14
any_destination must be a dtml method.
put in it this code:
<dtml-var REQUEST.form['Name']>
you'll receive a ms-dos application called 'any_destination.com' !!!
of course, that application is a text file containing    
'ewalstad@ewalstad.com'


Programmatic query strings by glenfant - 2005-09-17
Yeah, this rules for simple query strings, but if you want to introduce more complex query strings (with lists, dicts, dates, ...) you better use ZTUtils.make_query :

from ZTUtils import make_query

qs = make_query(param1=['a', 1], param2={'x': 1, y: 'okay'})
print qs