Additional argument in method GET

84 Views Asked by At

I would like to pass an additional argument in handling method GET in Python.

class Lista:
def GET(self):
    try:
        request = Request("")
        response_body = urlopen(request).read()
        decoded = json.loads(response_body)
        return render.list(content = decoded, user = decoded[0])
    except(ValueError, KeyError, TypeError):
        print "JSON format error"

class Mail:
    def GET(self):
    request = Request("")
    response_body = urlopen(request).read()
    decoded = json.loads(response_body)
    return render.mail(content = decoded, omail = decoded[0])

In class Lista downloading a list of objects from the Request URL and I render the HTML file "list". On the rendered page, I have a choice of several users. I would like to pass to the next class is what the user chose(by clicking).

Please help!

1

There are 1 best solutions below

0
On

I think you need something like unless I misunderstood:

class Lista:
    def GET(self,x=None):
        print x
        try:
            request = Request("")
            response_body = urlopen(request).read()
            decoded = json.loads(response_body)
            return render.list(content = decoded, user = decoded[0])
        except(ValueError, KeyError, TypeError):
            print "JSON format error"

Now it accepts a optional variable x, variable x is initialized to None just in case to need to send a empty request or so