How to read parameters from GET request in CherryPy?
Asked Answered
L

3

9

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 ?

Luminal answered 2/6, 2011 at 6:51 Comment(0)
I
14
@cherrypy.expose
def index(self, param)

where param is your GET param

Intussusception answered 2/6, 2011 at 7:14 Comment(0)
C
11

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

Also, you can read cherrypy.request.params.

Cypripedium answered 2/6, 2011 at 7:18 Comment(0)
B
8

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.

Brower answered 21/10, 2013 at 0:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.