给定这个简单的类:
class RenderResponseHandler(webapp2.RequestHandler):
def __init__(self):
self.nombreUsuario = obtenerUsuarioTablaUsuario().nombre if obtenerUsuarioTablaUsuario() else None
def doRender(self, tname='index.html',values = {}):
temp = os.path.join(os.path.dirname(__file__),
'templates/'+tname)
if not os.path.isfile(temp):
return False
self.nombreUsuario = obtenerUsuarioTablaUsuario().nombre if obtenerUsuarioTablaUsuario() else None
newval = dict(values)
newval['path'] = self.request.path
if nombreUsuario:
url_linktext = 'logout'
else:
url_linktext = 'login'
newval['url_linktext'] = url_linktext
newval['nombreUsuario'] = nombreUsuario
template = jinja_environment.get_template(tname)
outstr = template.render(newval)
self.response.out.write(outstr)
return True
def obtenerPagina(self, pOpcion = None, pMensajeInformacion = None):
opcion = pOpcion if pOpcion is not None else self.request.get('opcion')
if opcion == 'index':
self.doRender('index.html')
####
如果我这样做,页面会正常显示
class MainPage(webapp2.RequestHandler):
def get(self):
r = RenderResponseHandler()
r.request = self.request
r.response = self.response
r.obtenerPagina('index')
虽然,当尝试从 RenderResponseHandler 继承时,像这样:
class MainPage(RenderResponseHandler):
def get(self):
if self.doRender(self.request.path):
return
self.obtenerPagina('index')
我得到以下异常:
Traceback (most recent call last): File "/home/lucas/Dropbox/Tesis/Revision 2012/Desarrollo/Entorno/AppEngine SDK/google_appengine_1.6.6/lib/webapp2/webapp2.py", line 1536, in
__call__
rv = self.handle_exception(request, response, e) File "/home/lucas/Dropbox/Tesis/Revision 2012/Desarrollo/Entorno/AppEngine SDK/google_appengine_1.6.6/lib/webapp2/webapp2.py", line 1530, in
__call__
rv = self.router.dispatch(request, response) File "/home/lucas/Dropbox/Tesis/Revision 2012/Desarrollo/Entorno/AppEngine SDK/google_appengine_1.6.6/lib/webapp2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response) File "/home/lucas/Dropbox/Tesis/Revision 2012/Desarrollo/Entorno/AppEngine SDK/google_appengine_1.6.6/lib/webapp2/webapp2.py", line 1101, in
__call__
handler = self.handler(request, response) TypeError: __init__() takes exactly 1 argument (3 given)
我究竟做错了什么?
提前致谢!