[Zope] Python seems to render html, can this be turned off or escaped?

Guidry, Wayne wguidry at anteon.com
Thu Dec 16 11:28:50 EST 2004


You are correct that I was using <dtml-var expr="<functionName>"> to
obtain the value in DTML, however I changed that after I realized that
could be a problem and went into my python script and decided to test it
by clicking on the "Test" tab at the top of the python code and it still
rendered (which made me to believe it is the python that is rendering
it). 

Anyway, the code I am using looks like this:
(in python):

oldList = context.imageCoordsFile.data
newList = oldList.split("\n")
count=0
lstCount = len(newList)
returnList=[] 
tmpStr=""
for j in newList:
    imgList = j.split(',')
    xx1=convertx(float(imgList[1]))
    yy1=converty(float(imgList[2]))
    cx1=convertx(float(imgList[3])) #distance (radius) from center of
new x value
    cy1=converty(float(imgList[4])) #distance (radius) from center of
new y value
    cx1 = cx1 *.5 #reduce the size of the coordinate radius by 50%
(otherwise mapped images will overlap)
    cy1 = cy1 *.5
    xmin=int(xx1-cx1)
    xmax=int(xx1+cx1)
    ymin=int(yy1-cy1)
    ymax=int(yy1+cy1)
    newymin=x2-ymax
    newymax=x2-ymin
    #PROBLEM BEGINS ON LINE BELOW# 
    tmpStr = "<area shape = \"rect\" coords=\"" + str(xmin) +"," +
str(newymax) + "," + str(xmax) + "," + str(newymin) + "\" href =
\"<dtml-var BASE5>/selectWhereClause?currentid=<dtml-var
currentid>&selected=COM\"/>"
    returnList.append(tmpStr)
    count=count+1
return returnList

Now in DTML, I was calling it like this:
    <dtml-var "computeCoords()">

Perhaps the "Test" tab is using DTML to render the python also?!

If so, is there a way to force DTML not to render the text until I am
ready for it to do so?

Thanks again

-----Original Message-----
From: Jonathan Hobbs [mailto:toolkit at magma.ca] 
Sent: Thursday, December 16, 2004 10:19 AM
To: Guidry, Wayne; zope at zope.org
Subject: Re: [Zope] Python seems to render html,can this be turned off
or escaped?

From: "Guidry, Wayne" <wguidry at anteon.com>
> I am trying to pass a string into a dtml document (from python) that 
> contains html code, however I don't want python to render it, just 
> pass it.
>
> As an example...
>
> mystring = "<html><body<h1> test1 </h1></body></html>"
> return mystring
>
> 'mystring' needs to be returned to my DTML document as a string, not 
> as rendered html (which it seems to do automatically). Is this 
> possible to do?

I don't think python is converting the string to html.  What are you
doing with the string once it is in the dtml method (ie. how did you
invoke the python script?)

Something like:

<dtml-call "REQUEST.set('avar', myScript() )">

or

<dtml-let avar="myScript()">

should put the data from 'mystring' as text into the dtml variable
'avar'

if you do: <dtml-var myscript> then dtml will render the contents of
mystring to html

If you are still having problems, post another message with the dtml &
python code.

HTH

Jonathan








More information about the Zope mailing list