26
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.
24
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.
- [Django]-What is the absolute path of BASE DIR?
- [Django]-Django Admin nested inline
- [Django]-Django doesn't call model clean method
2
it doesnt look like they’re built in but here’s a couple snippets. it looks like it’d be pretty easy to create these helpers:
- [Django]-Detect mobile browser (not just iPhone) in python view
- [Django]-Meaning of leading underscore in list of tuples used to define choice fields?
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
1
Here is a list of all template tags and filters built into Django. Django core doesn’t have as much HTML helpers as Rails, because Django contributors assumed that web developer knows HTML very well. As stated by saturdaypalace, it’s very unlikely for AJAX helpers to be added to Django, because it would lead to coupling Django with a specific JavaScript library.
It’s very easy to write your own template tags in Django (often you need just to define one function, similiar to Rails). You could reimplement most of Rails helpers in Django during a day or two.
- [Django]-What does request.user refer to in Django?
- [Django]-How to fetch static CSS files with django on IIS?
- [Django]-What is the difference render() and redirect() in Django?
0
I bet if there would be any consent of what is common html, there would be helpers module too, just for completeness (or because others have it).
Other than that, Django template system is made mostly for HTML people, who already know how to write p
, img
and a
tags and do not need any helpers for that. On the other side there are Python developers, who write code and do not care if the variable they put in context is enclosed by div
or by span
(perfect example of separation of concerns paradigm). If you need to have these two worlds to be joined, you have do to it by yourself (or look for other’s code).
- [Django]-How to build a push system in django?
- [Django]-Query for top x elements in Django
- [Django]-How to return 404 page intentionally in django
-1
This won’t answer directly to the question, but why not using <a href="{% url mapper.views.foo %}">foo</a>
in template then?
- [Django]-Django CSRF framework cannot be disabled and is breaking my site
- [Django]-Python + Django page redirect
- [Django]-How do I use an UpdateView to update a Django Model?