Django是否有HTML助手? [英] Does Django have HTML helpers?
问题描述
{%url mapper.views.foo%}
但是,这只能给我一个URL,而不是HTML代码来创建链接。 Django有没有类似于Rails的link_to帮助?我发现 django-helpers ,但由于这是一个常见的事情,我认为Django会有东西内置。解决方案没有不。
James Bennett 回答了类似的问题,关于Rails的内置JavaScript助手。
真的不太可能,Django将内置帮助功能。原因如果我的理解正确,就需要与Django的核心理念保持一致。松散耦合。拥有这种内置的帮助功能可以将Django与特定的JavaScript库或(在您的情况下)html文档类型相结合。
EG。如果/当HTML 5最终实现并且Django正在生成HTML 4或XHTML标记时,会发生什么?
说到这一点,Django的模板框架是非常灵活的,很难编写自己的标签/过滤器做了你想要的我主要是一个设计师,我已经能够组合一些有魅力的自定义标签。
Does Django have any template tags to generate common HTML markup? For example, I know that I can get a url using
{% url mapper.views.foo %}
But that only gives me the URL and not the HTML code to create the link. Does Django have anything similar to Rails' link_to helper? I found django-helpers but since this is a common thing I thought Django would have something built-in.
解决方案 No it doesn't.
James Bennett answered a similar question a while back, regarding Rails' built-in JavaScript helpers.
It's really unlikely that Django will ever have 'helper' functionality built-in. The reason, if I understand correctly, has to do with Django's core philosophy of keeping things loosely coupled. Having that kind of helper functionality built-in leads to coupling Django with a specific JavaScript library or (in your case) html document type.
EG. What happens if/when HTML 5 is finally implemented and Django is generating HTML 4 or XHTML markup?
Having said that, Django's template framework is really flexible, and it wouldn't be terribly difficult to write your own tags/filters that did what you wanted. I'm mostly a designer myself, and I've been able to put together a couple custom tags that worked like a charm.
这篇关于Django是否有HTML助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!