5

I've a web-form that looks like:

<form action="/process_form/" method="post">
  <input type="text" name="login" value="login" />
  <input type="text" name="password" value="123" />
  <input type="submit" />
</form>

The python class to handle this is:

class Handle:
  @cherrypy.expose()
  #@cherrypy.tools.post <-- Is something like this possible
  def index(self, login=None):
    print(login)

Is there a way in CherryPy to restrict the call to /process_form/ to POST method? I mean if a user types http://www.example.com/process_form/ he/she should get an Exception/Error or page not found?

Mayank
  • 5,454
  • 9
  • 37
  • 60
  • http://tools.cherrypy.org/wiki/HTTPMethodFiltering. Haven't really used `cherrypy` that much. However, flipping through the documentation yielded me this. Check if you find it useful. – verisimilitude Mar 31 '13 at 10:21
  • CherryPy has native support for REST methods. Head for the documentation http://docs.cherrypy.org/dev/progguide/REST.html – Bibhas Debnath Mar 31 '13 at 10:43

1 Answers1

9

The Allow tool will raise a 405.

@cherrypy.tools.allow(methods=['POST'])
Craig Younkins
  • 1,360
  • 2
  • 11
  • 18
A. Coady
  • 54,452
  • 8
  • 34
  • 40