Does Django have HTML helpers?

前端 未结 6 2018
日久生厌
日久生厌 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 00:40

    The purpose of helpers is not, as others here imply, to help developers who don't know how to write HTML. The purpose is to encapsulate common functionality -- so you don't need to write the same thing a thousand times -- and to provide a single place to edit common HTML used throughout your app.

    It's the same reason templates and SSI are useful -- not because people don't know how to write the HTML in their headers and footers, but sometimes you want to write it just once.

    EG. What happens if/when HTML 5 is finally implemented and Django is generating HTML 4 or XHTML markup?

    Same thing that happens when HTML 5 is implemented and all your templates are written in repetitive HTML, except a lot easier.

    The other posts have already answered the question, linking to the docs on custom template tags; you can use tags and filters to build your own, but no, there aren't any built in.

提交回复
热议问题