Using Python26 on Windows 7 and latest webpy.
I copied the basic example (http://webpy.appspot.com/) for setting up Web.py on GAE, and followed the instructions for compiling templates for use with GAE (http://webpy.org/cookbook/templates_on_gae), but after doing so still have the ImportError: No module named templates.
Just to be clear: There are lots of people who have had this problem, and the solution is to compile the templates. I did this; still the same error.
My implementation is here: https://bitbucket.org/rhiaro/gae-tutorial (in webpyworld directory).
My main file, code.py is:
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()
Compiling the templates as instructed has resulted in the correct __ init __.py in the templates folder. But still it won't recognise it as a module.
The last part of the errors output:
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'
You're specifying templates/ as a static_dir in app.yaml.
This means it will not be available to application code, but will only be served directly in response to direct requests for the templates themselves by the user.