在GAE上使用web.py模板出现 No module named templates 错误的解决方法

在 GAE 环境使用 web.py 的模板系统会出现错误。原因大概是web.py使用了一些GAE环境受限的功能(猜的,没看代码)。
解决办法是在手工编译模板。
执行
python /usr/lib/python2.5/site-packages/web/template.py –compile templates

templates 是项目的模板目录,如果你的不是请修改。如果有多个模板目录都需要执行一次,每次修改模板也需要执行一次。

下面是错误提示:

Python 2.5.2: /usr/bin/python
Mon Feb 23 08:28:24 2009

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in _HandleRequest(self=)
2459 infile,
2460 outfile,
2461 base_env_dict=env_dict)
2462 finally:
2463 self.module_manager.UpdateModuleFileModificationTimes()
base_env_dict undefined, env_dict = {‘APPLICATION_ID’: ‘zcsino-dvd’, ‘CURRENT_VERSION_ID’: ‘1.1’, ‘REMOTE_ADDR’: ‘127.0.0.1’, ‘REQUEST_METHOD’: ‘GET’, ‘SERVER_NAME’: ‘localhost’, ‘SERVER_PORT’: ‘8080’, ‘SERVER_PROTOCOL’: ‘HTTP/1.0’, ‘SERVER_SOFTWARE’: ‘Development/1.0′}
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in Dispatch(self=, relative_url=’/’, path=None, headers=, infile=, outfile=, base_env_dict={‘APPLICATION_ID’: ‘zcsino-dvd’, ‘CURRENT_VERSION_ID’: ‘1.1’, ‘REMOTE_ADDR’: ‘127.0.0.1’, ‘REQUEST_METHOD’: ‘GET’, ‘SERVER_NAME’: ‘localhost’, ‘SERVER_PORT’: ‘8080’, ‘SERVER_PROTOCOL’: ‘HTTP/1.0’, ‘SERVER_SOFTWARE’: ‘Development/1.0’})
352 infile,
353 outfile,
354 base_env_dict=base_env_dict)
355
356 return
base_env_dict = {‘APPLICATION_ID’: ‘zcsino-dvd’, ‘CURRENT_VERSION_ID’: ‘1.1’, ‘REMOTE_ADDR’: ‘127.0.0.1’, ‘REQUEST_METHOD’: ‘GET’, ‘SERVER_NAME’: ‘localhost’, ‘SERVER_PORT’: ‘8080’, ‘SERVER_PROTOCOL’: ‘HTTP/1.0’, ‘SERVER_SOFTWARE’: ‘Development/1.0′}
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in Dispatch(self=, relative_url=’/’, path=’gae.py’, headers=, infile=, outfile=, base_env_dict={‘APPLICATION_ID’: ‘zcsino-dvd’, ‘CURRENT_VERSION_ID’: ‘1.1’, ‘REMOTE_ADDR’: ‘127.0.0.1’, ‘REQUEST_METHOD’: ‘GET’, ‘SERVER_NAME’: ‘localhost’, ‘SERVER_PORT’: ‘8080’, ‘SERVER_PROTOCOL’: ‘HTTP/1.0’, ‘SERVER_SOFTWARE’: ‘Development/1.0’})
1869 infile,
1870 outfile,
1871 self._module_dict)
1872 handler.AddDebuggingConsole(relative_url, env, outfile)
1873 finally:
self = , self._module_dict = {‘Cookie’: , ‘StringIO’: , ‘UserDict’: , ‘__builtin__’: , ‘__future__’: , ‘__main__’: , ‘_bisect’: , ‘_hashlib’: , ‘_random’: , ‘_struct’: , …}
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in ExecuteCGI(root_path=’/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd’, handler_path=’gae.py’, cgi_path=’/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/gae.py’, env={‘APPLICATION_ID’: ‘zcsino-dvd’, ‘AUTH_DOMAIN’: ‘gmail.com’, ‘CONTENT_LENGTH’: ”, ‘CONTENT_TYPE’: ‘application/x-www-form-urlencoded’, ‘CURRENT_VERSION_ID’: ‘1.1’, ‘GATEWAY_INTERFACE’: ‘CGI/1.1’, ‘HTTP_ACCEPT’: ‘text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8’, ‘HTTP_ACCEPT_CHARSET’: ‘GB2312,utf-8;q=0.7,*;q=0.7’, ‘HTTP_ACCEPT_LANGUAGE’: ‘zh-cn,zh;q=0.5’, ‘HTTP_CONNECTION’: ‘keep-alive’, …}, infile=, outfile=, module_dict={‘Cookie’: , ‘StringIO’: , ‘UserDict’: , ‘__builtin__’: , ‘__future__’: , ‘__main__’: , ‘_bisect’: , ‘_hashlib’: , ‘_random’: , ‘_struct’: , …}, exec_script=)
1787 logging.debug(‘Executing CGI with env:\n%s’, pprint.pformat(env))
1788 try:
1789 reset_modules = exec_script(handler_path, cgi_path, hook)
1790 except SystemExit, e:
1791 logging.debug(‘CGI exited with status: %s’, e)
reset_modules = True, exec_script = , handler_path = ‘gae.py’, cgi_path = ‘/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/gae.py’, hook =
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in ExecuteOrImportScript(handler_path=’gae.py’, cgi_path=’/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/gae.py’, import_hook=)
1683 try:
1684 if module_code:
1685 exec module_code in script_module.__dict__
1686 else:
1687 script_module.main()
module_code = <code object at 0x85e2380, file “/mnt/s…g/mpython/gae/project/zcsino-dvd/gae.py”, line 5>, script_module = , script_module.__dict__ = {‘__builtins__’: {‘ArithmeticError’: , ‘AssertionError’: , ‘AttributeError’: , ‘BaseException’: , ‘DeprecationWarning’: , ‘EOFError’: , ‘Ellipsis’: Ellipsis, ‘EnvironmentError’: , ‘Exception’: , ‘False’: False, …}, ‘__doc__’: None, ‘__file__’: ‘/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/gae.py’, ‘__loader__’: , ‘__name__’: ‘gae’, ‘import_wrapper’: }
/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/gae.py in ()
4 # 优先使用自带库
5 import import_wrapper
6 import views
7
8
views undefined
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in decorate(self=, *args=(‘views’,), **kwargs={})
847 self._indent_level += 1
848 try:
849 return func(self, *args, **kwargs)
850 finally:
851 self._indent_level -= 1
func = , self = , args = (‘views’,), kwargs = {}
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in load_module(self=, fullname=’views’)
1443 search_path = parent_module.__path__
1444
1445 return self.FindAndLoadModule(submodule, fullname, search_path)
1446
1447 @Trace
self = , self.FindAndLoadModule = <bound method HardenedModulesHook.decorate of >, submodule = ‘views’, fullname = ‘views’, search_path = None
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in decorate(self=, *args=(‘views’, ‘views’, None), **kwargs={})
847 self._indent_level += 1
848 try:
849 return func(self, *args, **kwargs)
850 finally:
851 self._indent_level -= 1
func = , self = , args = (‘views’, ‘views’, None), kwargs = {}
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in FindAndLoadModule(self=, submodule=’views’, submodule_fullname=’views’, search_path=None)
1351 source_file,
1352 pathname,
1353 description)
1354
1355 module.__loader__ = self
description = (‘.py’, ‘U’, 1)
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in decorate(self=, *args=(‘views’, , ‘/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/views.py’, (‘.py’, ‘U’, 1)), **kwargs={})
847 self._indent_level += 1
848 try:
849 return func(self, *args, **kwargs)
850 finally:
851 self._indent_level -= 1
func = , self = , args = (‘views’, , ‘/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/views.py’, (‘.py’, ‘U’, 1)), kwargs = {}
/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py in LoadModuleRestricted(self=, submodule_fullname=’views’, source_file=, pathname=’/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/views.py’, description=(‘.py’, ‘U’, 1))
1301 source_file,
1302 pathname,
1303 description)
1304 except:
1305 if submodule_fullname in self._module_dict:
description = (‘.py’, ‘U’, 1)
/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/views.py in ()
6 import config
7
8 render = web.template.render(‘templates/’, base=’base’)
9
10 urls = (
render undefined, web = None, web.template undefined, base undefined
/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/libs/web.zip/web/template.py in __init__(self=, loc=’templates/’, *a=(), **kw={‘base’: ‘base’})

: No module named templates
args = (‘No module named templates’,)
message = ‘No module named templates’

INFO 2009-02-23 08:28:24,069 dev_appserver.py] “GET / HTTP/1.1” 500 –
ERROR 2009-02-23 08:28:25,806 dev_appserver.py] Exception encountered handling request
Traceback (most recent call last):
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 2461, in _HandleRequest
base_env_dict=env_dict)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 354, in Dispatch
base_env_dict=base_env_dict)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 1871, in Dispatch
self._module_dict)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 1789, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 1685, in ExecuteOrImportScript
exec module_code in script_module.__dict__
File “/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/gae.py”, line 6, in
import views
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 849, in decorate
return func(self, *args, **kwargs)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 1445, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 849, in decorate
return func(self, *args, **kwargs)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 1353, in FindAndLoadModule
description)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 849, in decorate
return func(self, *args, **kwargs)
File “/mnt/source/home/gamexg/mpython/gae/google_appengine/google/appengine/tools/dev_appserver.py”, line 1303, in LoadModuleRestricted
description)
File “/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/views.py”, line 8, in
render = web.template.render(‘templates/’, base=’base’)
File “/mnt/source/home/gamexg/mpython/gae/project/zcsino-dvd/libs/web.zip/web/template.py”, line 995, in __init__
ImportError: No module named templates

在GAE上使用web.py模板出现 No module named templates 错误的解决方法》上有4条评论

  1. bugs

    我看GAE上的说明,好像把web.py的模块放在GAE的项目文件夹中可以索引就可以了,可是却一直无法运行,一直提示找不到flup,能指教一下怎样把web.py这个框架怎样使用到GAE上么?

发表评论

电子邮件地址不会被公开。