Ad

Does Django Have HTML Helpers?

- 1 answer

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.

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad