我尝试使用pyramid_layout包进行应用的声明性配置。我想只在configure.zcml文件中配置它。
这是:
<configure xmlns="http://pylonshq.com/pyramid"
xmlns:lat="http://pylonshq.com/pyramid_layout">
<include package="pyramid_zcml" />
<include package="pyramid_layout" file="meta.zcml"/>
<static
name="static"
path="static"
/>
<!-- layouts -->
<lat:layout
name="test"
layout=".layouts.AppLayout"
template="templates/layouts/layout1.pt"
/>
<!-- default view -->
<view
view=".views.my_view"
renderer="templates/home.pt"
lat:layout="test"
/>
<view
name="two"
view=".views.my_view2"
renderer="templates/mytemplate2.pt"
/>
</configure>
当我调用默认视图时 - 得到一个例外:
NameError: main_template
- Expression: "main_template"
- Filename: ... o\python_test\pyramid7\myzcml1\myzcml1\templates\home.pt
- Location: (line 4: col 25)
- Source: <metal:block use-macro="main_template">
^^^^^^^^^^^^^
- Arguments: repeat: {...} (0)
renderer_name: templates/home.pt
req: <Request - at 0x4a96be0L>
request: <Request - at 0x4a96be0L>
档案home.pt:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal" >
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<h1>It is home view</h1>
<p>Hello home.pt template</p>
<p>Project is: ${project}</p>
</div>
</metal:block>
</html>
BTW,如果我在view.my_view代码中使用request.layout_manager.use_layout(&#34; test&#34;) - 它运行正常!
我在代码中做错了什么?那么,是否可以以这种方式使用pyramid_layout?有可能吗?