Cherrypy: Can't get my POST data
I write a tiny webapp with CherryPy. But I has a problem - I can't get my POST data, but GET is ok. Hosted on local host (Win 7), viewed with Opera 10, using CherryPy built-in server.
Here is some code:
class Expose:
def __init__(self, fn):
self.fn = fn
@cherrypy.expose()
def index(self, login=None):
print 'LOGIN: ' + str(login)
return self.fn(login=login)
import auth
root.process_form = Expose(auth.process_form)
This is is my URL switch. LOGIN prints None if form uses POST, and proper value for GET. Here is my form (template):
<!DOCTYPE html>
<body>
<p>Create new user</p>
<form action="/process_form" method="post">
<input type="text" name="login" value="login" />
<input type="text" name="email" value="me@company.com" />
<input type="text" name="password" value="123" />
<input type="submit" />
</for开发者_如何学编程m>
</body>
I can't guess what goes wrong. What may I check?
Try with:
<!DOCTYPE html>
<body>
<p>Create new user</p>
<form action="/process_form/" method="post">
<input type="text" name="login" value="login" />
<input type="text" name="email" value="me@company.com" />
<input type="text" name="password" value="123" />
<input type="submit" />
</form>
</body>
Note the final slash in "/process_form/
I don't know if root.processform is something special in CherryPy, if not you need to expose a process_form page
@cherrypy.expose()
def process_form(self, email, login,password):
...stuff...
I may be missing something
精彩评论