2012-05-07 29 views
3

私はPythonとGoogle App Engineの新機能です。私はwebapp2とpython 2.7を使用するためにNick Johnsonのブログからこのコードをリファクタリングしようとしています。 http://blog.notdot.net/2009/10/Blogging-on-App-Engine-part-1-Static-servingこのTypeErrorを修正するにはどうすればよいですか?

とにかく、以下のコードを実行すると、このエラーが発生します。

TypeError: get() takes exactly 2 arguments (1 given)

私は、定義されていないpath変数と何か関係があるかもしれないと思いますが、定義方法はわかりません。

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) 
+0

@systempuntooutはあなたに答えを与えたが、私は、このように取得メソッドを呼び出し、それを使用することはありません取得ハンドラで。これにより問題が発生する可能性があります。 – aschmid00

+0

スタックトレースからほぼすべての有用な情報を削除しました。最後の行だけでなく、将来の完全なスタックトレースも含めてください。 –

答えて

1

MainHandlerクラスのget方法はpathパラメータを期待するので、エラーが発生します。
あなたがget方法にpathパラメータを渡すためにあなたのルーティング定義内の正規表現にグループ化を追加する必要があります

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

それはそれでした。ありがとう! – Busilinks

関連する問題