简体   繁体   English

Web设计人员的Python模板

[英]Python templates for web designers

What are some good templating engines for web designers? 什么是网页设计师的好模板引擎? I definitely have my preferences as to what I'd prefer to work with as a programmer. 我绝对喜欢我喜欢与程序员合作的东西。 But web designers seem to have a different way of thinking about things and thus may prefer a different system. 但网页设计师似乎有不同的思考方式,因此可能更喜欢不同的系统。

So: 所以:

  • Web designers: what templating engine do you prefer to work with? 网页设计师:您更喜欢使用什么模板引擎?
  • programmers: what templating engines have you worked with that made working with web designers easy? 程序员:你使用过哪些模板引擎,这使得与网页设计师合作变得容易?

Django's templating engine is quite decent. Django的模板引擎相当不错。 It's pretty robust while not stepping on too many toes. 它非常强大,而不是踩太多脚趾。 If you're working with Python I would recommend it. 如果您正在使用Python,我会推荐它。 I don't know how to divorce it from Django, but I doubt it would be very difficult seeing as Django is quite modular. 我不知道如何将它与Django分开,但我怀疑看到Django非常模块化会非常困难。

EDIT: Apparently the mini-guide to using Django's templating engine standalone was sitting in front of me already, thanks insin . 编辑:显然, 独立使用Django的模板引擎迷你指南已经在我面前,感谢insin

I had good votes when answering this same question's duplicate . 回答同一个问题时,我有很好的选票。

My answer was: 我的回答是:

Jinja2 . Jinja2

Nice syntax , good customization possibilities . 良好的语法 ,良好的定制可能性

Integrates well. 整合得很好。 Can be sandboxed, so you don't have to trust completely your template authors. 可以沙盒,因此您不必完全信任您的模板作者。 (Mako can't). (Mako不能)。

It is also pretty fast, with the bonus of compiling your template to bytecode and cache it, as in the demonstration below: 它也非常快,可以将模板编译为字节码并对其进行缓存,如下面的演示:

>>> import jinja2
>>> print jinja2.Environment().compile('{% for row in data %}{{ row.name | upper }}{% endfor %}', raw=True) 
from __future__ import division
from jinja2.runtime import LoopContext, Context, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join
name = None

def root(context, environment=environment):
    l_data = context.resolve('data')
    t_1 = environment.filters['upper']
    if 0: yield None
    for l_row in l_data:
        if 0: yield None
        yield unicode(t_1(environment.getattr(l_row, 'name')))

blocks = {}
debug_info = '1=9'

This code has been generated on the fly by Jinja2. 此代码由Jinja2即时生成。 Of course the compiler optmizes it further (eg removing if 0: yield None ) 当然编译器会进一步优化它(例如,删除if 0: yield None

Look at Mako . 看看Mako

Here's how I cope with web designers. 这是我如何应对网页设计师。

  1. Ask them to mock up the page. 让他们模拟页面。 In HTML. 在HTML中。
  2. Use the HTML as the basis for the template, replacing the mocked-up content with ${...} replacements. 使用HTML作为模板的基础,用${...}替换替换模拟的内容。
  3. Fold in loops to handle repeats. 折叠循环以处理重复。

The use of if-statements requires negotiation, since the mock-up is one version of the page, and there are usually some explanations for conditional presentation of some material. 使用if语句需要协商,因为模型是页面的一个版本,并且通常对某些材料的条件表示有一些解释。

I personally found Cheetah templates to be very designer-friendly. 我个人发现Cheetah模板非常适合设计师。 What needed some time was the idea of templates subclassing, and this was something hard to get at the beginning. 需要一些时间的是模板子类化的想法,这在开始时很难得到。 But a designer creates a full template, duplicating his code... Then you can go clean things up a bit. 但是设计师会创建一个完整的模板,复制他的代码......然后你可以去清理一下。

To add to @Jaime Soriano's comment, Genshi is the template engine used in Trac post- 0.11. 要添加到@Jaime索里亚诺的评论, 元史是在Trac系统中使用的模板引擎后置信0.11。 It's can be used as a generic templating solution, but has a focus on HTML/XHTML. 它可以用作通用模板解决方案,但重点是HTML / XHTML。 It has automatic escaping for reducing XSS vulnerabilities. 它具有自动转义功能,可以减少XSS漏洞。

Mi vote goes to Clearsilver , it is the template engine used in Trac before 0.11, it's also used in pages like Google Groups or Orkut. Mi投票给了Clearsilver ,它是Trac在0.11之前使用的模板引擎,它也用在Google Groups或Orkut这样的页面中。 The main benefits of this template engine is that it's very fast and language-independent. 这个模板引擎的主要好处是它非常快速且与语言无关。

I've played both roles and at heart I prefer more of a programmer's templating language. 我扮演了两个角色,但我更喜欢程序员的模板语言。 However, I freelance for a few graphic designers doing the "heavy lifting" backed and db programming and can tell you that I've had the best luck with XML templating languages (SimpleTAL, Genshi, etc). 但是,我是一些自由职业者为一些图形设计师做了“繁重的”支持和数据库编程,并且可以告诉你我已经用XML模板语言(SimpleTAL,Genshi等)获得了最好的运气。

When I'm trying to be web designer friendly I look for something that can be loaded into Dreamweaver and see results. 当我想成为网页设计师友好的时候,我会寻找可以加载到Dreamweaver中并查看结果的内容。 This allows me to provide all the hooks in a template and let the designer tweak it without worrying about breaking what I've already written. 这允许我在模板中提供所有钩子,让设计师调整它,而不用担心破坏我已经写过的东西。 It allows us to share the code and work better together where we're both comfortable with the format. 它允许我们共享代码并在我们对格式感到满意的情况下更好地协同工作。

If the designer codes without a WYSIWYG editor, I think you're options are less limited and you could go with your own personal favorite. 如果设计师在没有WYSIWYG编辑器的情况下编码,我认为你的选择不那么有限,你可以选择自己喜欢的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM