Does Django have HTML helpers?

前端 未结 6 2015
日久生厌
日久生厌 2021-02-07 00:04

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 %}

Bu

6条回答
  •  情书的邮戳
    2021-02-07 01:02

    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.

提交回复
热议问题