Re: [Django] #35602: Allow simple_tag to be defined and used in a for loop

10 views
Skip to first unread message

Django

unread,
Jul 16, 2024, 5:56:01 AM (yesterday) Jul 16
to django-...@googlegroups.com
#35602: Allow simple_tag to be defined and used in a for loop
-------------------------------------+-------------------------------------
Reporter: Henrique Lacreta | Owner: (none)
Alves |
Type: New feature | Status: closed
Component: Template system | Version: 4.2
Severity: Normal | Resolution: wontfix
Keywords: tag, simple_tag | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Henrique Lacreta Alves):

Fair point, I didn't consider using "as", and it does seem a bit of a
stretch extending the use of "simple_tag" when such a simple solution
already exists.

One thing I would consider though would be to add this as an example on
Documentation. Using "simple_tag" as an iterable looks like a quite common
scenario, and replacing it by an inclusion tag is an overkill most of the
time. Do you think this would make sense/should I create a documentation
suggestion?
--
Ticket URL: <https://code.djangoproject.com/ticket/35602#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 16, 2024, 6:38:16 AM (yesterday) Jul 16
to django-...@googlegroups.com
#35602: Allow simple_tag to be defined and used in a for loop
-------------------------------------+-------------------------------------
Reporter: Henrique Lacreta | Owner: (none)
Alves |
Type: New feature | Status: closed
Component: Template system | Version: 4.2
Severity: Normal | Resolution: wontfix
Keywords: tag, simple_tag, | Triage Stage:
forloop | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* cc: Baptiste Mispelon, Tom Carrick, Carlton Gibson (added)
* keywords: tag, simple_tag => tag, simple_tag, forloop

Comment:

On your earlier point that `{% for object in ""|filter_tag %}` works,
#19882 is related.
I might have been too hasty and am not sure whether this should be a bug
as you originally thought. Going to invite some other opinions

> Do you think this would make sense/should I create a documentation
suggestion?

Possibly, though the docs for the **as** argument of
[https://docs.djangoproject.com/en/5.0/howto/custom-template-
tags/#django.template.Library.simple_tag simple_tag] read quite well to me
--
Ticket URL: <https://code.djangoproject.com/ticket/35602#comment:3>

Django

unread,
Jul 16, 2024, 8:42:47 AM (yesterday) Jul 16
to django-...@googlegroups.com
#35602: Allow simple_tag to be defined and used in a for loop
-------------------------------------+-------------------------------------
Reporter: Henrique Lacreta | Owner: (none)
Alves |
Type: New feature | Status: closed
Component: Template system | Version: 4.2
Severity: Normal | Resolution: wontfix
Keywords: tag, simple_tag, | Triage Stage:
forloop | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Carlton Gibson):

Looking at the
[https://github.com/django/django/blob/082fe2b5a83571dec4aa97580af0fe8cf2a5214e/django/template/defaulttags.py#L777
code for do_for()], this usage could never have been intended, so agreed
it would be a new feature.

Would that be worthwhile? I'd want a proof-of-concept showing what it
might look like before saying. (The existing `as` approach is perfectly
serviceable, if arguably less fluent.)
--
Ticket URL: <https://code.djangoproject.com/ticket/35602#comment:4>

Django

unread,
1:51 AM (18 hours ago) 1:51 AM
to django-...@googlegroups.com
#35602: Allow simple_tag to be defined and used in a for loop
-------------------------------------+-------------------------------------
Reporter: Henrique Lacreta | Owner: (none)
Alves |
Type: New feature | Status: closed
Component: Template system | Version: 4.2
Severity: Normal | Resolution: wontfix
Keywords: tag, simple_tag, | Triage Stage:
forloop | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tom Carrick):

I've always known / thought that you can't use tags in other tags like
this, but you can use filters. This seems like the expected behaviour to
me. If it's worth doing or not, don't really have an opinion, I would
suggest it's not really worth it as `simple_tag` already supports `as`,
which is intended for this kind of thing.

And I think if we did this for `simple_tag`, people would undoubtedly
wonder why it doesn't work for any tag, as they look identical in the
template code. And that would be more effort, and would add to the allowed
complexity of the template engine, which is against it's design ideals to
keep templates simple (IMO). Better to put this type of logic in the view
or use jinja if you need this kind of thing.

Improved docs are always nice, but I would say this isn't a bug.
--
Ticket URL: <https://code.djangoproject.com/ticket/35602#comment:5>
Reply all
Reply to author
Forward
0 new messages