2012-04-04 65 views
1

在Windows 7和最新的webpy上使用Python26。ImportError:没有在Google App Engine上使用带有Web.py DESPITE的模板命名模板已编译模板

我复制了用于在GAE上设置Web.py的基本示例(http://webpy.appspot.com/),并遵循了编译用于GAE的模板的说明(http://webpy.org/ cookbook/templates_on_gae),但这样做后仍然有ImportError:No模块命名模板。

要明确一点:有很多人有这个问题,解决方案是编译模板。我做到了;仍然是同样的错误。

我的实施在这里: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() 

编译模板的指示,导致在模板文件夹的正确初始化__ __.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' 
+0

您需要至少包含完整的堆栈跟踪和导致它的代码。 – 2012-04-05 09:23:02

+0

@NickJohnson:源代码位于链接顶部的git存储库中,但完整的堆栈跟踪仍然丢失 – KitB 2012-04-05 11:04:01

回答

1

你指定的模板/在app.yaml中一个static_dir。

这意味着它将不可用于应用程序代码,但只会直接响应用户对模板本身的直接请求。

+0

问题出在哪里 - 谢谢! – rhiaro 2012-04-05 14:01:44