Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CherryPy: How to restrict a route to POST-only

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?

like image 597
Mayank Avatar asked Mar 31 '13 10:03

Mayank


1 Answers

The Allow tool will raise a 405.

@cherrypy.tools.allow(methods=['POST'])
like image 103
A. Coady Avatar answered Sep 30 '22 06:09

A. Coady