Nevow XML Templates

nevow:Web 应用程序构建工具包 divmod 更新 Divmod Nevow 是一个用 Python 编写的 Web 应用程序构建工具包。 它旨在允许程序员根据需要在 Python 中表达尽可能多的视图逻辑,并包含一个名为 stan 的纯 Python XML 表达式语法来促进这一点。 然而,它还为设计者编辑的模板提供了丰富的支持,使用非常小的 XML 属性语言来提供双向模板操作能力。 Nevow 还包括 Divmod Athena,这是一个“双向网络”或“ ”实现,提供了服务器上的 Python 代码和客户端上的 JavaScript 代码之间的双向桥梁。 页面的模块化部分,在服务器 python 中称为“athena 片段”,在客户端 javascript 中称为“athena 小部件”,可以单独开发并放置在任何带有小型模板渲染器的 Nevow 渲染页面上。 Athena 在一个简单的远程方法调用接口背后抽象了 立即下载
 
1Nevow XML Templates
2===================
3
4Stan syntax is cool, but eventually you are going to want to integrate your
5Python code with a template designed by an HTML monkey. Nevow accomplishes this
6by providing an xmlfile loader which uses the built-in Python SAX libraries to
7generate a tree of stan behind the scenes. The general rule is anything that is
8possible in stan should be possible in a pure XML template; of course, the XML
9syntax is generally going to be much more verbose.
10
11* `loaders.xmlfile`_
12* `Nevow's xmlns declaration`_
13* `Nevow's Tag Attribute Language`_
14* `nevow:render`_
15* `Built-in renderers`_
16* `nevow:data`_
17* `nevow:pattern`_
18* `nevow:slot`_
19* `nevow:attr`_
20* `nevow:invisible`_
21* `xmlstr, htmlfile, and htmlstr`_
22
23loaders.xmlfile
24---------------
25
26Wherever you have seen a loaders.stan being created in any of the example code,
27a loaders.xmlfile can be substituted instead. At the most basic, xmlfile merely
28requires the name of an xml template::
29
30  class HelloXML(rend.Page):
31      docFactory = loaders.xmlfile('hello.xml')
32
33Placing the following xml in the hello.xml file will cause HelloXML to display a
34static page when it is rendered::
35
36  <html>Hello, world!</html>
37
38The following additional keyword arguments may be given to xmlfile to configure
39it:
40
41templateDirectory
42  The path to the directory which contains the template file. Defaults to ''.
43
44ignoreDocType   
45  If True, discard any DOCTYPE declaration when building the DOM from this
46  template. When false, preserve the DOCTYPE, causing it to show up in the final
47  output. Useful for when you are inserting an XML fragment into a larger page
48  and do not wish to generate invalid XML as output. Defaults to False.
49
50ignoreComment
51  If True, discard XML comments, causing them to disappear from the output. If
52  False, preserve comments and render them in the final output unchanged.
53  Defaults to False.
54
55pattern
56  If present, the given pattern name will be looked up and used as the root of
57  the template. If not present, the entire document will be used as the
58  template. Useful for embedding fragments of an XML document in a larger page.
59  Defaults to None.
60
61Nevow's xmlns declaration
62-------------------------
63
64In order for Nevow to notice and process any XML directives in the template
65file, you must declare the Nevow xmlns at the top of your XML document. Nevow's
66xmlns is::
67
68  http://nevow.com/ns/nevow/0.1
69
70The syntax for declaring that your xml document uses this namespace is::
71
72  <html xmlns:nevow="http://nevow.com/ns/nevow/0.1"></html>
73
74You may replace the text "nevow" in the above example with any name you choose.
75For example, many people use "n" because it is shorter to type. If you do so, be
76sure to replace all occurrences of the nevow namespace in the examples with the
77namespace name you choose.
78
79Nevow's Tag Attribute Language
80------------------------------
81
82The markup you will add to your XHTML file in order to invoke Nevow code
83consists mostly of namespaced tag attributes. This approach was influenced
84heavily by the Zope Page Templates (ZPT) Tag Attribute Language (TAL). However,
85I felt that TAL did not go far enough in removing control flow and branching
86possibilities from the XML template. Nevow's main philosophy is that it should
87be as easy as possible to move from the XML document into Python code, and that
88the Python code should have ultimate control over manipulating the structure of
89the XML template.
90
91The key is that it is easy to expose Python methods that you write to your XML
92template, and it is easy for the XML templates to mark nodes which it wishes the
93Python method to manipulate. In this way, if either the Python implementation
94changes or the location or content of the marked nodes change in the XML
95template, the other side will be isolated from these changes.
96
97Nevow's XML templating has two attributes which invoke Python code:
98
99* nevow:render -- Invokes a Python method and replaces the template node with the result
100* nevow:data -- Invokes a Python method and sets the data special for the node to the result
101
102It has one attribute which marks nodes as manipulatable by Python code:
103
104* nevow:pattern -- Gives a node a name so that Python code may clone and mutate copies of this node
105
106It also has two namespaced tags:
107
108* nevow:slot -- Works in the same way as the slot attribute
109* nevow:attr -- Indicates that an attribute of the parent tag should be manipulated by Python code in some way
110
111nevow:render
112------------
113
114When the nevow:render attribute is encountered, the xmlfile loader sets the
115render special to a directive constructed with the attribute value. When the
116template is rendered, this means that the appropriate render_* method will be
117looked up on the IRendererFactory (generally the Page instance)::
118
119  <html><div nevow:render="foo" /></html>
120
121With the render_foo method::
122
123  def render_foo(self, ctx, data):
124      return "Hello"
125
126Will result in the document::
127
128  <html>Hello</html>
129
130Note that the return value of the render method replaces the template node in
131the DOM, so if you want the template node to remain, you should use ctx.tag.
132
133Built-in renderers
134------------------
135
136Nevow comes with various built in renderers on the Page class.
137
138data
139  Renders the current data as-is inside the current node.
140
141string
142  Renders the current data as a string inside the current node.
143
144sequence
145  Iterates the current data, copying the "item" pattern for each item. Sets the
146  the data special of the new node to the item, and inserts the result in the
147  current node. See the nevow.rend.sequence docstring for information about
148  other used patterns, including "header", "divider", "footer" and "empty".
149
150mapping
151  Calls .items() on the current data, and calls ctx.fillSlots(key, value) for
152  every key, value pair in the result. Returns the template tag.
153
154xml
155  Inserts the current data into the template after wrapping it in an xml
156  instance. Not very useful in practice.
157
158nevow:data
159----------
160
161When the nevow:data attribute is encountered, the xmlfile loader sets the data
162special of the current node to a directive constructed with the attribute value.
163When the template is rendered, this means that the appropriate data_* method
164will be looked up on the current IContainer (generally the Page instance). The
165data_* method will be called, and the result will be set as the data special of
166the current Tag::
167
168  <html><div nevow:data="name" nevow:render="data" /></html>
169
170With the data_name method::
171
172  def data_name(self, ctx, data):
173      return "Hello!"
174
175Will result in the document::
176
177  <html><div>Hello!</div></html>
178
179Note that with a data attribute on a node but no renderer, the result of the
180data method will be set as the data special for that tag, and child render
181methods will be passed this data.
182
183nevow:pattern
184-------------
185
186When the nevow:pattern attribute is encountered, the xmlfile loader sets the
187pattern special of the current node to the attribute value as a string.
188Renderers which are above this node may then make copies of it using the
189nevow.inevow.IQ of the current context. With the template::
190
191  <html nevow:render="stuff"><div nevow:pattern="somePattern" nevow:render="data" /></html>
192
193And the renderer::
194
195  def render_stuff(self, ctx, data):
196      pat = inevow.IQ(ctx).patternGenerator('somePattern')
197      return [pat(data=1), pat(data=2)]
198
199Will result in the document::
200
201  <html><div>1</div><div>2</div></html>
202
203nevow:slot
204----------
205
206When the nevow:slot tag is encountered, the xmlfile loader constructs a
207nevow.stan.slot instance, passing the name attribute value as the slot name. The
208children of the slot node are added as children of the new slot instance. This
209is useful if you wish to put patterns inside the slot. With the template::
210
211  <html nevow:render="stuff"><nevow:slot name="slotName" /></html>
212
213And the render method::
214
215  def render_stuff(self, ctx, data):
216      ctx.fillSlots('slotName', "Hello.")
217      return ctx.tag
218
219This document will be produced::
220
221  <html>Hello.</html>
222
223nevow:attr
224----------
225
226When the nevow:attr tag is encountered, the contents of the nevow:attr node will
227be assigned to the attribute of the parent tag with the name of the value of the
228name attribute. Perhaps an example will be a little clearer::
229
230  <html><a><nevow:attr name="href">HELLO!</nevow:attr>Goodbye</a></html>
231
232This document will be produced::
233
234  <html><a href="HELLO!">Goodbye</a></html>
235
236While this syntax is somewhat awkward, every other type of nevow tag and
237attribute may be used inside the nevow:attr node. This makes setting attributes
238of tags uniform with every other method of manipulating the XML template.
239
240nevow:invisible
241---------------
242
243Sometimes you need to group some elements, because you need to use a
244renderer for a group of children.
245
246However, it may not be desirable to give these elements a parent/child
247relationship in your XML structure.  For these cases, use nevow:invisible.
248
249As suggested by the name, a nevow:invisible tag is removed in the rendered
250XML. Here is an example::
251 
252  <html><nevow:invisible nevow:data="name" nevow:render="data" /></html>
253
254With the data_name method::
255
256  def data_name(self, ctx, data):
257      return "Hello!"
258
259Will result in the document::
260
261 <html>Hello!</html>
262
263xmlstr, htmlfile, and htmlstr
264-----------------------------
265
266xmlstr is a loader which is identical to xmlfile except it takes a string of XML
267directly.
268
269htmlfile and htmlstr should generally be avoided. They are similar to xmlfile
270and xmlstr, except they use twisted.web.microdom in beExtremelyLenient mode to
271attempt to parse badly-formed HTML (non-XHTML) templates. See the nevow.loaders
272docstrings for more information.
273
274Conclusions
275===========
276
277Nevow's xmlfile tag attribute language allows you to integrate
278externally-designed XHTML templates into the Nevow rendering process.
279
Stateflow使用C语言结构体,关于使用Stateflow调用外部C代码的教程介绍 无论是Simulink仿真,还是对模型做代码生成,已有C代码的调用都是我们经常会遇到的情形:如何调用现有的外部C代码?很多人首先想到的是S-Function。的确,S-Function提供了一种途径,可以让我们把C函数封装成Simulink模块在Simulink环境下运行。另外还有一种方式,叫做Legacy Code Tool,说白了也是S-Function,只是MATLAB提供了这样的接口便于用... 阅读详情

相关推荐

青藏高原冻土数据实战:如何用QGIS分析1961-2020年冻土退化趋势(附完整操作步骤)

本文详细介绍了如何使用QGIS分析1961-2020年青藏高原冻土退化趋势,包括数据准备、预处理、时空分析和模型验证等全流程操作。通过TTOP模型和Stefan方程,揭示了冻土退化的空间差异和海拔依赖性,为环境研究提供科学依据。

weixin_29276847的博客 127

读取xml报错问题not well-formed (invalid token): line 52, colum16

在获得想要的节点后,修改节点标签名称,然后设置xml保存的编码方式和格式属性,确保读入xml和写入后的xml文件格式保持不变。然后dom = xml.dom.minidom.parse(xml_file)例如:在xml中存在L(B*W)=DN但是python打开后出现乱码。这种情况可以先打开xml文件,其中metaxml是xml的路径字段。2、若xml中出现特殊字符,导致文件无法读取报错。就可以打开xml文件并可以读取xml的相关节点。1、若xml中出现中文字段。3、若xml修改后格式变化。

qq_43645067的博客 2049

超详细!DeepSeek本地搭建部署、搭建知识库及智能体教程

通过以上详细的步骤,我们完成了DeepSeek的本地搭建部署、知识库的搭建以及智能体的创建。这一过程不仅让我们深入了解了大模型的应用,还为我们开发个性化的智能应用奠定了基础。在实际应用中,可以根据具体需求进一步优化模型、知识库和智能体的性能和功能。希望本文能帮助大家快速上手DeepSeek相关技术,开启属于自己的人工智能创新之旅。

Ljugg的博客 8185

一篇介绍Nevow的非常好的文章,推荐

Nevow: A Web Application Construction Kit Donovan Preston &lt;dp@divmod.org &gt; Summary Nevow is a web application construction kit, based on the ideas developed in the Twisted Woven pack...

pythoner的专栏 360

【Qt串口调试助手】1.1 - Qt5编写串口调试助手,Qt串口编程

这章来学习串口数据流操作。仿照成品制作一个自己用Qt编写的串口助手。 1. 布局UI界面 创建QWidget工程,布局UI界面:拖入2个 Plain Text Edit,作为串口数据的接收显示和发送框。 拖入几个 Combo Box 、Label 和 Push Button,使用两个Widget进行布局。如下所示。 将接收区的 Plain Text Edit,属性勾选上 readOnly,使其运行时不会被人为的输入操作影响。 加入一些弹簧,使布局美观。(有必要可以加设置不能调整..

Mark_md的博客 9274

动量因子在A股市场的有效性分析:量化实证研究

验证动量因子在A股市场的有效性及时间周期性分析不同时间窗口(短期/中期/长期)对动量效应的影响量化交易成本、市场流动性对动量策略收益的侵蚀程度比较A股与成熟市场(如美股)动量效应的差异特征理论框架:行为金融学解释动量效应的产生机制技术实现:Python全流程代码实现动量因子计算与回测实证分析:统计检验、风险收益指标、敏感性分析应用拓展:结合市场微观结构的策略优化方案动量因子(Momentum Factor)

2501_92132293的博客 2480

小型Python Web框架 Nevow

Nevow ,python web, zhoubols, 周波

周波的个人博客 1195

基金估值核算系统三国杀:恒生 VS 赢时胜 VS 融选!

本文对比分析了恒生电子、赢时胜和融选科技三家金融科技公司的基金估值系统。恒生电子作为行业龙头,在公募基金领域占据较大份额,其新一代估值系统6.0采用微服务架构,自动化程度高;赢时胜在中型公募和券商资管领域优势明显,其V5.5系统在信创适配和复杂产品处理方面表现突出;融选科技作为新兴厂商,提供轻量化解决方案,适合中小型机构。文章从市场格局、系统定位、技术架构、成本构成和用户反馈五个维度进行深入比较,为金融机构选型提供参考。当前估值系统市场呈现"三国鼎立"格局,各具特色,选型需结合机构规模、

magbox520的博客 826

使用twisted+nevow框架简单实例

 1. 首先,编写一个HTML文件,helloword.html      Hello, world!        Hello, world!  2. 编写一个Nevow控制程序文件,helloword.pyfrom nevow import loaders, rendclass HelloWorld(rend.Pa

pythoner的专栏 878

Hermes 教程 03:Skills 系统

摘要:Hermes Skills是一种自我改进机制,可将解决问题的经验保存为可复用技能文档。v0.13.0版本遵循agentskills.io开放标准,与Claude Skills互通。技能创建流程包括发现问题、创建技能文件、加载使用和优化更新四个阶段。系统提供技能检索和自维护机制(Curator),支持技能媒体路由和多种管理命令。内置技能涵盖开发调试、创意头脑风暴等场景,通过积累技能使Hermes更适应用户需求。

程序猿_三产 730

Dify框架面试内容整理-如何进行Dify的二次开发?

无论是轻量修改界面,还是深度集成自定义模型、Agent、知识库,你都可以很方便地进行二次开发。,你可以基于它的开源架构对功能进行扩展、集成第三方服务、修改界面风格,甚至定制新的AI工作流程。前端:Node.js >= 16,React + TypeScript + Tailwind。接入自己的模型API(如:调用LLaMA、Baichuan、ChatGLM)。修改路径:/api/app/services/providers/可接入你自己的向量数据库(Qdrant、Milvus、FAISS)

不务正业的猿 2003

AssertionError: Badly …

使用 gtk-builder-convert glade_hxw.glade glade_hxw.xml 最后出现如下错误 AssertionError: Badly formed XML, there is no tag. 解决方法 使用文本编辑工具打开 glade_hxw.glade,修改其中的,改成 修改为

极客剑 955

【异常】Cursor IDE 扩展主机超时错误处理文档The agent execution provider did not respond within 4 seconds.

该错误通常是 Cursor IDE 的临时性问题,不影响项目代码。大多数情况下,重新加载窗口或重启 IDE 即可解决。如果问题持续,可按上述进阶方案排查。重新加载窗口(最快)重启 IDE检查系统资源清理缓存检查扩展更多关于 AI+教育领域的干货,可以关注我的微信公众号第一时间获取哦~

奶爸的编程之路,也就一周冷个三天 2700

使用XMLTemplater写出XML

原文地址:https://knowledge.safe.com/articles/30940/xml-writing-with-xmltemplater.html 介绍         XML是一种结构化的文本形式,常用于开放标准和交换格式。也常出现在Web和消息传递应用程序中。将数据转换成XML格式是FME的一项重要功能。本文介绍编写XML的FME方法,并且以基本的示例帮

GIS骆驼的GIS博客 3192

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Nevow拥有很好的新特性

引用:Nevow , a python based web construction toolkit , has a lot of nice features, that deserve attention:1 - LivePage ( Ajax ).2 - Canvas ( Flash to server ).3 - XUL , the python way.4 - Stan ( Python

pythoner的专栏 565

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

eclipse的xml文件提示templates的模板

eclipse的xml文件提示templates的模板 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <templates> <template autoinsert="true" context="xml_tag" enable...

weixin_33841722的博客 395

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

MyEclipse中xml的区别xml(advanced Templates)、xml(Basic Templates)、xml schema

advanced Templates是struts插件带的新建XML向导,可以根据Struts的配置创建基于Struts的web.xml和Struts配置文件。  Basic Templates是Eclipse带的新建XML向导,可以根据任意的DTD和Schema生成XML schema是定义和限制另一个xml文件的文件。

sunhongruihuifeideyu的专栏 3424

glade工具安装及入门

glade工具安装及入门 1.glade工具安装    这个工具还是很好安装的,只需一个命令:sudo apt-get install glade libglade2-dev 2.几个重要的问题    glade图形工具还是很好操作的,基本上拉一拉,熟悉熟悉应该都会。接下来是几个比较难处理的问题    glade产生的界面还是要通过代码来实现的,保存的.glade文件要转化成.xml文件

black_yu的博客 2638

获取xml时,出现“(十六进制值 0x1F)是无效的字符之类Xml异常的解决办法

http://hi.baidu.com/zeratul_bb/blog/item/3e2a44cf085cf33af8dc61de.html获取xml时,出现“(十六进制值 0x1F)是无效的字符之类Xml异常的解决办法2008-12-19 10:44最近做新闻采集器,需要获取很多站点的xml,加载个别站点经常出现“(十六进制值 0x1F)是无效的字符”问题,百思不

jiljil的专栏 7728

Nevow render用法(转)

_uacct = "UA-99018-3";urchinTracker();1Nevow Object Publishing2=======================34In Nevow Object Traversal, we learned about the5nevow.inevow.IResource.renderHTT

pythoner的专栏 816

error: Error parsing XML: not well-formed (invalid token)解决办法

从另一个工程中拷贝代码到新的工程后,编译出现了error: Error parsing XML: not well-formed (invalid token)错误,刚开始不清楚怎么解决。重新拷贝编译,也还是同样的问题。后来进入到工程中对相应的.xml文件cat看了下,发现里边全部是一些二进制的信息或者乱码。         这才发现问题所在,改用ftp服务器上传的方式后问题解决。      

5375

配置codetemplates.xml

/** * ${tags} */ /** * ${tags} * @功能描述: * @Author:Kvin0829 * @date:${date} ${time} * @Version:1.1.0 */ /** * @return the ${bare_field_name} */ /** @param ${param} the ${bare_field

Kvin0829的博客 1193
上一篇: Nevow-traversal (转)
下一篇: Nevow XML Templates
pythoner
博客等级 码龄18年 15粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值