Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read parameters from GET request in CherryPy?

How to read parameters from GET request in CherryPy ? I generate request from JQuery like

$.get(
    "http://localhost:8080/temp",
    "{a:10}",
    function(data) { alert(data); },
    "html"
);

and I have class temp with @cherrypy.expose function index(self). How to extract data from GET request ?

like image 220
Jana Avatar asked Jun 02 '11 06:06

Jana


3 Answers

@cherrypy.expose
def index(self, param)

where param is your GET param

like image 85
virhilo Avatar answered Oct 31 '22 19:10

virhilo


As virhilo mentioned, you can take named parameters in with your method.

Also, you can read cherrypy.request.params.

like image 23
Ken Kinder Avatar answered Oct 31 '22 18:10

Ken Kinder


With both POST and GET (and PUT, PATCH, etc...) you can use:

cherrypy.request.params.get(key_name)

Where key_name is the key name you want to get.

like image 8
ocodo Avatar answered Oct 31 '22 18:10

ocodo