I have the name of a file that I am passing into the page template using my_url?fileid="foo". I then want to access the properties of that file from within the zpt. my zpt looks like: <html> <body tal:define="dentist here/REQUEST/fileid"> <span tal:replace="container/dentist/firstName">first_name</span> <span tal:replace="container/dentist/lastName">last_name</span> <br> <span tal:replace="container/dentist/city">first name</span> <br> </body> </html> The error I get is: Error Type: TypeError Error Value: sequence index must be integer Does anyone know what I'm doing wrong? Thanks.
Daniel Tartaglia wrote at 2003-8-22 11:49 -0400:
I have the name of a file that I am passing into the page template using my_url?fileid="foo". I then want to access the properties of that file from within the zpt.
my zpt looks like: <html> <body tal:define="dentist here/REQUEST/fileid"> <span tal:replace="container/dentist/firstName">first_name</span> <span tal:replace="container/dentist/lastName">last_name</span> <br> <span tal:replace="container/dentist/city">first name</span> <br> </body> </html>
The error I get is: Error Type: TypeError Error Value: sequence index must be integer
Apparently, "container/dentist" is a property with a sequence value. Therefore, "container/dentist/<something>" raises the above TypeError. You should use: "container/?dentist/<something>". This will evaluate "dentist" and use the result in the path (e.g. "foo" instead of the constant "dentist"). Dieter
I have the name of a file that I am passing into the page template using my_url?fileid="foo". I then want to access the properties of that file from within the zpt.
my zpt looks like: <html> <body tal:define="dentist here/REQUEST/fileid"> <span tal:replace="container/dentist/firstName">first_name</span> <span tal:replace="container/dentist/lastName">last_name</span> <br> <span tal:replace="container/dentist/city">first name</span> <br> </body> </html>
The error I get is: Error Type: TypeError Error Value: sequence index must be integer
Does anyone know what I'm doing wrong? Thanks.
Think carefully about types. The object you refer to with 'here/REQUEST/fileid', and thus 'dentist', is a string. You cannot say 'container/dentist/firstName' and have Zope understand that you want to use the contents of the string variable 'dentist' when what you really wrote was a path expression saying that you wanted something named 'dentist'. This as if in Python you said:: dentist = "somefilename" print someobject.dentist.property Obviously it looks for a property named 'dentist' on someobject. (Think of this in, say, Java and it becomes even more obivous.) This is what Zope does in your example, and since you don't have anything named 'dentist' in your container, it gives you a TypeError. You can get contents/attributes/properties based on the contents of a string. In Python, this means 'getattr' or element access (using square brackets). Possibly you could also use 'restrictedTraverse'. There was a great post on this not very long ago. Try to look it up. (A shell scripting language might solve this by variable expansion, such that 'container/$dentist/firstName' would do what you want. I don't believe TALES supports this sort of thing.) --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
participants (3)
-
Daniel Tartaglia -
Dieter Maurer -
J Cameron Cooper