将 Mako 与 Pyramid 结合使用会导致错误
当尝试将 Mako 与 Pyramid 框架一起使用时,通过进入development.ini 文件,并添加以下行
mako.directories = TestProject:templates
:
[app:TestProject]
然后在 templates 子目录中创建一个名为 template.mako 的简单 html 文件,我得到一个:
ImportError: No module named TestProject
但我无法理解为什么这是在上述步骤之后发生的。为什么这些步骤会生成导入错误?
错误的更多详细信息:
URL: http://localhost:6543/
File 'C:\\env\\lib\\site-packages\\weberror-0.10.3-py2.7.egg\\weberror\\evalexception.py', line 431 in respond
app_iter = self.application(environ, detect_start_response)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\router.py', line 158 in __call__
response = view_callable(context, request)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\config.py', line 2839 in _rendered_view
context)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 294 in render_view
request=request)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 322 in render_to_response
result = self.render(value, system_values, request=request)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 298 in render
renderer = self.renderer
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\decorator.py', line 17 in __get__
val = self.wrapped(inst)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 280 in renderer
return factory(self)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\mako_templating.py', line 77 in renderer_factory
directories = [ abspath_from_asset_spec(d) for d in directories ]
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\asset.py', line 207 in abspath_from_asset_spec
return pkg_resources.resource_filename(pname, filename)
File 'C:\\env\\lib\\site-packages\\setuptools-0.6c12dev_r88124-py2.7.egg\\pkg_resources.py', line 881 in resource_filename
File 'C:\\env\\lib\\site-packages\\setuptools-0.6c12dev_r88124-py2.7.egg\\pkg_resources.py', line 201 in get_provider
ImportError: No module named TestProject
When trying to use Mako with the Pyramid framework, by going into the development.ini file, and adding the line
mako.directories = TestProject:templates
in:
[app:TestProject]
and then creating a simple html file called template.mako in the templates subdirectory I get an:
ImportError: No module named TestProject
But I fail to understand why this is happening after the above steps. Why are those steps generating an importError?
More detials of the error:
URL: http://localhost:6543/
File 'C:\\env\\lib\\site-packages\\weberror-0.10.3-py2.7.egg\\weberror\\evalexception.py', line 431 in respond
app_iter = self.application(environ, detect_start_response)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\router.py', line 158 in __call__
response = view_callable(context, request)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\config.py', line 2839 in _rendered_view
context)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 294 in render_view
request=request)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 322 in render_to_response
result = self.render(value, system_values, request=request)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 298 in render
renderer = self.renderer
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\decorator.py', line 17 in __get__
val = self.wrapped(inst)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\renderers.py', line 280 in renderer
return factory(self)
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\mako_templating.py', line 77 in renderer_factory
directories = [ abspath_from_asset_spec(d) for d in directories ]
File 'C:\\env\\lib\\site-packages\\pyramid-1.0-py2.7.egg\\pyramid\\asset.py', line 207 in abspath_from_asset_spec
return pkg_resources.resource_filename(pname, filename)
File 'C:\\env\\lib\\site-packages\\setuptools-0.6c12dev_r88124-py2.7.egg\\pkg_resources.py', line 881 in resource_filename
File 'C:\\env\\lib\\site-packages\\setuptools-0.6c12dev_r88124-py2.7.egg\\pkg_resources.py', line 201 in get_provider
ImportError: No module named TestProject
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
摘要:
编辑文件
development.ini
并在[app:MyProject]
部分添加:现在我们可以打开文件
/MyProject/myproject/__init__.py
并添加如下行:这将渲染位于以下位置的模板:
/MyProject/myproject/templates/foo.mako
注意:MyProject 和 myproject 是您的项目的名称。尊重案件。
请记住在
生产.ini
文件中进行相同的配置!编辑:我在金字塔的1.3a1版本(2011-12-09)更新日志中的功能部分看到:
As summary:
Edit the file
development.ini
and add in the section[app:MyProject]
:Now we can open the file
/MyProject/myproject/__init__.py
and add a line like:This will render the template located in:
/MyProject/myproject/templates/foo.mako
Note: MyProject and myproject are the name of YOUR project. Respect the case.
Remember to do the same configuration in
production.ini
file!Edit:I see in the 1.3a1 version of pyramid (2011-12-09) Changelog in the Features section:
发生这种情况是因为 mako.templates 规范的格式为 package:directory。因此,在您的情况下,您必须有一个名为“TestProject”的包。
您的项目可能有一个包,但它显然不被称为“TestProject”。
It happens because the mako.templates specifiction is in the format of package:directory. Therefore you must have a package called, in your case, "TestProject".
You may have a package for your project, but it's apparently not called "TestProject".