我该如何解决这个TypeError?

时间:2012-05-07 09:48:58

标签: google-app-engine

我是python和Google App Engine的新手。我正在尝试从Nick Johnson博客重构此代码以使用webapp2和python 2.7。 http://blog.notdot.net/2009/10/Blogging-on-App-Engine-part-1-Static-serving

无论如何,当我运行下面的代码时,我得到了这个错误。

  

TypeError:get()只需要2个参数(给定1个)

我认为它可能与未定义的路径变量有关,但我不知道如何定义它。

import webapp2
from google.appengine.ext import webapp
from google.appengine.ext import db

class StaticContent(db.Model):
    body = db.BlobProperty()
    content_type = db.StringProperty(required=True)
    last_modified = db.DateTimeProperty(required=True, auto_now=True)

def get(path):
    return StaticContent.get_by_key_name(path)

def set(path, body, content_type, **kwargs):
    content = StaticContent(
        key_name=path,
        body=body,
        content_type=content_type,
        **kwargs)
    content.put()
    return content

class MainHandler(webapp2.RequestHandler):

    def get(self, path):
        content = get(path)
        if not content:
            self.error(404)
            return
app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)

1 个答案:

答案 0 :(得分:1)

引发错误是因为get类的MainHandler方法需要path参数。
您应该将分组添加到路由定义中的正则表达式,以将path参数传递给get方法:

app = webapp2.WSGIApplication([('(/.*)', MainHandler)],
                              debug=True)
相关问题