Search code examples
pythonpostgetcherrypy

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="[email protected]" />
  <input type="text" name="password" value="123" />
  <input type="submit" />
</form>

</body>

I can't guess what goes wrong. What may I check?


Solution

  • 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="[email protected]" />
      <input type="text" name="password" value="123" />
      <input type="submit" />
    </form>
    
    </body>
    

    Note the final slash in "/process_form/