供网页设计师使用的 Python 模板

发布于 2024-07-08 05:28:27 字数 179 浏览 7 评论 0 原文

对于网页设计师来说,有哪些好的模板引擎? 作为一名程序员,我肯定有自己的偏好。 但网页设计师似乎有不同的思考方式,因此可能更喜欢不同的系统。

那么:

  • 网页设计师:您更喜欢使用哪种模板引擎?
  • 程序员:您使用过哪些模板引擎可以让与网页设计师的合作变得轻松?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

暗恋未遂 2024-07-15 05:28:27

回答同一问题的重复时,我投了很好的票。

我的答案是:

Jinja2

不错的语法,不错的自定义可能性

整合得很好。 可以沙盒化,因此您不必完全信任模板作者。 (马科不能)。

它的速度也相当快,好处是可以将模板编译为字节码并缓存它,如下面的演示所示:

>>> 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'

该代码是由 Jinja2 动态生成的。 当然,编译器会进一步优化它(例如删除if 0:yield None

I had good votes when answering this same question's duplicate.

My answer was:

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).

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. Of course the compiler optmizes it further (e.g. removing if 0: yield None)

硬不硬你别怂 2024-07-15 05:28:27

Django 的模板引擎 相当不错。 它非常坚固,同时不会踩到太多脚趾。 如果您正在使用 Python,我会推荐它。 我不知道如何将它与 Django 分开,但我怀疑这会很困难,因为 Django 是相当模块化的。

编辑:显然独立使用 Django 模板引擎的迷你指南已经在我面前了,谢谢因辛

Django's templating engine is quite decent. It's pretty robust while not stepping on too many toes. If you're working with Python I would recommend it. I don't know how to divorce it from Django, but I doubt it would be very difficult seeing as Django is quite modular.

EDIT: Apparently the mini-guide to using Django's templating engine standalone was sitting in front of me already, thanks insin.

少女情怀诗 2024-07-15 05:28:27

看看 Mako

以下是我与网页设计师打交道的方式。

  1. 请他们模拟该页面。 在 HTML 中。
  2. 使用 HTML 作为模板的基础,用 ${...} 替换内容替换模拟内容。
  3. 折叠循环以处理重复。

if 语句的使用需要协商,因为模型是页面的一个版本,并且通常对某些材料的条件呈现有一些解释。

Look at Mako.

Here's how I cope with web designers.

  1. Ask them to mock up the page. In HTML.
  2. Use the HTML as the basis for the template, replacing the mocked-up content with ${...} replacements.
  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.

苍白女子 2024-07-15 05:28:27

我个人发现 Cheetah 模板 对设计师来说非常友好。 需要一些时间的是模板子类化的想法,而这在一开始是很难实现的。 但是设计师创建了一个完整的模板,复制了他的代码......然后你可以稍微清理一下。

I personally found Cheetah templates to be very designer-friendly. 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.

怪我闹别瞎闹 2024-07-15 05:28:27

添加到 @Jaime Soriano 的评论,Genshi 是 Trac 0.11 后使用的模板引擎。 它可以用作通用模板解决方案,但重点关注 HTML/XHTML。 它具有自动转义功能,可减少 XSS 漏洞。

To add to @Jaime Soriano's comment, Genshi is the template engine used in Trac post- 0.11. It's can be used as a generic templating solution, but has a focus on HTML/XHTML. It has automatic escaping for reducing XSS vulnerabilities.

郁金香雨 2024-07-15 05:28:27

Mi投票去Clearsilver,它是Trac 0.11之前使用的模板引擎,也用于像这样的页面Google 网上论坛或 Orkut。 该模板引擎的主要优点是速度非常快并且与语言无关。

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. The main benefits of this template engine is that it's very fast and language-independent.

天赋异禀 2024-07-15 05:28:27

我扮演过这两个角色,从内心来说,我更喜欢程序员的模板语言。 然而,我是一些图形设计师的自由职业者,从事“繁重”的支持和数据库编程,并且可以告诉您,我在 XML 模板语言(SimpleTAL、Genshi 等)方面运气很好。

当我试图成为网页设计师友好的人时,我会寻找可以加载到 Dreamweaver 中并查看结果的东西。 这使我能够在模板中提供所有挂钩,并让设计人员对其进行调整,而不必担心破坏我已经编写的内容。 它使我们能够共享代码,并在我们都熟悉格式的情况下更好地合作。

如果设计师在没有所见即所得编辑器的情况下进行编码,我认为您的选择受到的限制较少,您可以选择自己喜欢的。

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).

When I'm trying to be web designer friendly I look for something that can be loaded into Dreamweaver and see results. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文