Daniel Watson
Daniel Watson

Reputation: 473

python 2.7 google app engine custom request/response

Google app engine in python can access the request and response objects with self.request and self.response (within the handler). I'm building a custom parent handler class, and while I have many useful shortcuts, the request/response order is lost. Is there a way in which I can build my own Request and Response classes to initialize them in the parent handler? I added this to my code:

class Request(webapp2.Request):
    pass

class Response(webapp2.Response):
    pass

Then, I added these to the constructor of my custom class:

class HandlerBase(webapp2.RequestHandler):
    def __init__(self, *a, **kw):
        self.request = Request()
        self.response = Response()

This throws an error: TypeError: __init__() takes at least 2 arguments (1 given) I obviously don't know what the missing argument is, but I know it's a dictionary (a WSGI environment (whatever that means, I don't know), according to the error) Does anyone know what to do?

Upvotes: 0

Views: 86

Answers (1)

Daniel Watson
Daniel Watson

Reputation: 473

class Webapp(webapp2.WSGIApplication):

    request_class = Request
    response_class = Response

It seems you only need to create a child application class with the variables. It works perfectly. Creating instances in the handler class is not needed.

Upvotes: 1

Related Questions