#34124: Developer experience on {% with %} template tag can be improved.
-------------------------------------+-------------------------------------
Reporter: oscarmcm | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Template | Version: 4.1
system |
Severity: Normal | Keywords: template tag
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The "with" template tag just caches a complex variable under a simpler
name, and from the Django Documentation we know that there's two ways to
use this tag:
- normal form
{{{
{% with alpha=1 beta=2 %}
{% endwith %}
}}}
- verbose form
{{{
{% with business.employees.count as total %}
{% endwith %}
}}}
But recently I was reviewing some code and found this:
{{{
{% with first_post_image as post_images.first.image %}
...
{% endwith %}
}}}
As we can see the order of the parameters is wrong, I was a bit surprised
that the Django template engine did not throw or raised an issue while
trying to render the template, and in the same way I think the ticket
#32157 is directly related to this. So I believe that we can improve the
DX for this template tag and enforce the values that we want to cache,
this means that we should allow only valid variable names and enforce
value casting.
--
Ticket URL: <https://code.djangoproject.com/ticket/34124>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701841a224919-db0eea78-f6ab-404d-8757-b67a2ce10594-000000%40eu-central-1.amazonses.com.