[英]Pyramid, Chameleon and template rendering
I started a project with the Python web framwork 'Pyramid', using the template engine 'chameleon'. 我使用模板引擎'chameleon'开始了一个使用Python web框架'Pyramid'的项目。
I'm a beginner of this frameworks, but I have to use it for a customer. 我是这个框架的初学者,但我必须将它用于客户。
I follow the steps in order to install the framework, then I started coding, just for training purpose! 我按照步骤安装框架,然后我开始编码,仅用于培训目的!
My first application was a stupid, simple CRUD application. 我的第一个应用程序是一个愚蠢的,简单的CRUD应用程序。
What I'm doing is: 我在做的是:
in my __init__.py
I have, for each view, the following code: 在我的
__init__.py
中,对于每个视图,我都有以下代码:
config.add_view('myenglishdictionary.views.modify',route_name='modify_route',renderer='templates/base.pt') config.add_view( 'myenglishdictionary.views.modify',ROUTE_NAME = 'modify_route',渲染= '模板/ base.pt')
base.pt is the main template with header and footer and a div with the following code: base.pt是带有页眉和页脚的主模板,以及带有以下代码的div:
<div>${body}</div>
in my file view.py each view has 2 lines like the following: 在我的文件view.py中,每个视图都有2行,如下所示:
body = render('templates/list.pt',{'list':list ,'project':'myProject'}, request=request)
return {'body':body}
and in my list.pt there is the content which will be embedded in base.pt 在我的list.pt中有内容将嵌入base.pt.
All seemed to work good. 一切似乎都很好。 But after an update of the libraries, now I can't see my template correctly.
但是在更新库之后,现在我无法正确地看到我的模板。
Instead the actual html code there are html entities: 相反,实际的html代码有html实体:
<div class="clear"></div>
so, obviously the page doesn't look well. 所以,显然页面看起来不太好。
The problems seems to be in the render method, since the html of base.pt template is displayed correctly. 问题似乎出现在render方法中,因为base.pt模板的html正确显示。
Using the ${}
syntax escapes the included text by default (to help defend against XSS injection attacks). 使用
${}
语法默认转义包含的文本(以帮助防御XSS注入攻击)。
Instead, use the structure:
prefix to tell the rendering engine to not escape your text: 相反,使用
structure:
前缀来告诉渲染引擎不要转义您的文本:
<div>${structure: body}</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.