Windows 7 と最新の webpy で Python26 を使用します。
GAE で Web.py をセットアップするための基本的な例 (http://webpy.appspot.com/) をコピーし、GAE で使用するテンプレートをコンパイルするための指示に従いました (http://webpy.org/cookbook/templates_on_gae)。 、しかし、その後もまだ ImportError: No module named templates があります。
はっきりさせておきたいのですが、この問題を抱えている人はたくさんいます。解決策は、テンプレートをコンパイルすることです。これは私がしました; それでも同じエラー。
私の実装はここにあります: https://bitbucket.org/rhiaro/gae-tutorial (webpyworld ディレクトリ内)。
私のメインファイル code.py は次のとおりです。
from google.appengine.ext import db
import web
urls = (
'/', 'index',
'/note', 'note',
'/crash', 'crash'
)
render = web.template.render('templates/')
class Note(db.Model):
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
class index:
def GET(self):
notes = db.GqlQuery("SELECT * FROM Note ORDER BY date DESC LIMIT 10")
return render.index(notes)
class note:
def POST(self):
i = web.input('content')
note = Note()
note.content = i.content
note.put()
return web.seeother('/')
class crash:
def GET(self):
import logging
logging.error('test')
crash
app = web.application(urls, globals())
def main():
app.cgirun()
if __name__ == '__main__':
main()
指示に従ってテンプレートをコンパイルすると、テンプレート フォルダーに正しい __ init __.py が作成されます。しかし、それでもモジュールとして認識されません。
エラー出力の最後の部分:
path\to\webpyworld\code.py in ()
8 )
9
10 render = web.template.render('templates/')
11
12 class Note(db.Model):
render undefined, web = <module 'web' from 'D:\gaeTut\webpyworld\web\__init__.pyc'>, web.template = <module 'web.template' from 'D:\gaeTut\webpyworld\web\template.py'>, web.template.render = <class web.template.GAE_Render>
path\to\webpyworld\web\template.py in __init__(self=<web.template.GAE_Render instance>, loc='templates/', *a=(), **kw={})
1031 else:
1032 name = loc.rstrip('/').replace('/', '.')
1033 self.mod = __import__(name, None, None, ['x'])
1034
1035 self.mod.__dict__.update(kw.get('builtins', TEMPLATE_BUILTINS))
self = <web.template.GAE_Render instance>, self.mod undefined, builtin __import__ = <built-in function __import__>, name = 'templates', builtin None = None
<type 'exceptions.ImportError'>: No module named templates
args = ('No module named templates',)
message = 'No module named templates'