[Twisted-Python] how to get form values in woven?
Mike Mueller
pyp at gmx.net
Thu Jan 8 21:16:12 MST 2004
I am just starting with woven. I couldn't find a simple example how to get
the values from a submitted form. Reading the HOWTOs and searching the
twisted mail archives as well as web didn't bring up what I was searching for.
An example:
from twisted.application import service, internet
from twisted.web.woven import page
from twisted.web import server, resource
class FirstPage(page.Page):
template = """<html>
<head>
<title>First Form</title>
</head>
<body>
<h3>First Form</h3>
<form action="processMyForm" method="post">
<p>
Text1:
<input type="text" id="Text1"/><br/>
Text2:
<input type="text" id="Text2"/><br/>
<input type="submit" value="Send"/>
</p>
</form>
</body>
</html>
"""
def initialize(self, *args, **kwargs):
self.numberOfProcessCalls = 0
def wchild_processMyForm(self, request):
self.numberOfProcessCalls += 1
keysValues = []
for k, v in request.__dict__.items():
keysValues.append('%s:\t %s' %(k,v))
model = {'keys-values': keysValues,
'number':self.numberOfProcessCalls}
return page.Page(model, template=
"""<html>
<body>
Number of calls:
<p model="number" view="Text" />
<h3>arg keys: values</h3>
<div model="keys-values" view="List">
<p pattern="listItem" view="Text" />
</div>
</body>
</html>""")
p = FirstPage()
application = service.Application('SimpleForm')
internet.TCPServer(8088,
server.Site(resource.IResource(p))).setServiceParent(service.IServiceCollection(application))
There are several problems with this.
1.) wchild_processMyForm gets called twice every time the submit button is hit
2.) for the first call the method is post for, the second it is get
3.) arg is always {}, so nothing to process
Obviously, I am doing something wrong. Basically I just want to echo back
the name/values pairs that where entered into the form. How do I do this
with woven?
Thanks
Mike
More information about the Twisted-Python
mailing list