khateeb
khateeb

Reputation: 5469

Getting TypeError in Google App Engine

I am writing a simlpe web application in Python using GAE. My response.out.write is giving me TypeError. The error message is:

self.response.out.write(*a, **kw)
TypeError: write() takes exactly 2 arguments (3 given)

The python code is:

import os

import jinja2
import webapp2

template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir))

class Handler(webapp2.RequestHandler):

    def write(self, *a, **kw):
        self.response.out.write(*a, **kw)

    def render_str(self, template, **kw):
        t = jinja_env.get_template(template)
        return t.render(kw)

    def render(self, template, **kw):
        self.write(self, self.render_str(template, **kw))

class MainHandler(Handler):

    def get(self):
      self.render("shopping_list.html", name="steve")


app = webapp2.WSGIApplication([('/', MainHandler),],
                             debug=True)

Upvotes: 1

Views: 150

Answers (1)

alecxe
alecxe

Reputation: 473863

You don't need to explicitly pass self to the write() method.

Replace:

self.write(self, self.render_str(template, **kw))

with:

self.write(self.render_str(template, **kw))

Upvotes: 1

Related Questions