Re: [Django] #2594: Template system should handle whitespace better

29 views
Skip to first unread message

Django

unread,
May 5, 2011, 2:43:09 PM5/5/11
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary | Owner: jshedd
Wilson <gary.wilson@…> | Status: new
Type: Bug | Component: Template system
Milestone: | Severity: Normal
Version: SVN | Keywords:
Resolution: | Has patch: 1
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 1 |
-------------------------------------+-------------------------------------
Changes (by patchhammer):

* needs_better_patch: 0 => 1
* easy: => 0


Comment:

0001-Commiting-whitespace-patch-from-django-ticket-2594.2.patch fails to
apply cleanly on to trunk

--
Ticket URL: <http://code.djangoproject.com/ticket/2594#comment:35>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 24, 2012, 9:18:50 AM2/24/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: SVN
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by tobia):

I just started a thread about an alternative solution to this problem.

Newline stripping in templates: the dnl way

http://groups.google.com/group/django-
developers/browse_thread/thread/8d6b6a3aae82ee03

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:37>

Django

unread,
Feb 29, 2012, 7:50:35 AM2/29/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: SVN
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by kmike):

* cc: kmike84@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:38>

Django

unread,
Mar 30, 2012, 3:24:17 PM3/30/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: SVN
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by andrep):

* cc: andrep (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:39>

Django

unread,
Apr 7, 2012, 9:55:16 AM4/7/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: SVN
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Twidi):

* cc: Twidi (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:40>

Django

unread,
Apr 14, 2012, 5:29:49 AM4/14/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: SVN
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

Please someone from django core sacrifice a day, and test and ad this to
1.4.x. Thanks a lot!

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:41>

Django

unread,
May 3, 2012, 5:05:28 AM5/3/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Semmel):

* cc: Florian.Sening@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:42>

Django

unread,
May 6, 2012, 8:30:16 AM5/6/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by waldir):

* cc: waldir (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:43>

Django

unread,
Jun 13, 2012, 2:35:18 PM6/13/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by ldiqual@…):

* cc: ldiqual@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:44>

Django

unread,
Jun 27, 2012, 5:38:37 PM6/27/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by leonov):

* cc: python@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:45>

Django

unread,
Jun 27, 2012, 8:25:26 PM6/27/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by leonov):

I've spent the morning updating the patch against the latest development
version.

It was fairly straightforward, except for the `Lexer.create_token()`
method, which took some time. It was already fairly hairy in 1.4, and the
addition of the `verbatim` tag in 1.5-dev had made it even more so. I've
added comments to make it easier for the next person to unravel the logic.

All tests pass, pre- and post-patch, and the results of Gary Wilson's
benchmark remain good.

{{{
python -m timeit -n500 -s 'from bm import my_render' 'my_render()'

Without patch:
500 loops, best of 3: 1.96 msec per loop
500 loops, best of 3: 1.95 msec per loop
500 loops, best of 3: 1.96 msec per loop

With patch, TEMPLATE_STRIP_LEADING_WHITESPACE = True:
500 loops, best of 3: 1.96 msec per loop
500 loops, best of 3: 1.96 msec per loop
500 loops, best of 3: 1.97 msec per loop

With patch, TEMPLATE_STRIP_LEADING_WHITESPACE = False:
500 loops, best of 3: 1.99 msec per loop
500 loops, best of 3: 2 msec per loop
500 loops, best of 3: 2.01 msec per loop
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:46>

Django

unread,
Dec 4, 2012, 9:31:02 AM12/4/12
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by BinaryKhaos):

* cc: ua_django_bugzilla@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:47>

Django

unread,
Jan 23, 2013, 8:09:29 PM1/23/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by s.shanabrook@…):

* cc: s.shanabrook@… (added)


Comment:

What needs to be done to get this merged still?

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:48>

Django

unread,
Jan 23, 2013, 8:19:22 PM1/23/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by mrmachine):

You could try reading through the ticket and django-developers group
history so that you're familiar with all the options and opinions that
have been presented. Then outline a proposal on the django-developers
group to move the ticket forward by choosing a preferred option (probably
the one which had the most support), summarise why it has been chosen over
any others, update any patches so that they apply cleanly and ask for a
code review and any final objections that would delay this being
committed.

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:49>

Django

unread,
Feb 26, 2013, 6:20:51 AM2/26/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

Why not implement the {%- tag -%} support in Jinja2, and let people choose
themselves?

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:50>

Django

unread,
Aug 3, 2013, 7:14:20 PM8/3/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by chipx86):

* cc: chipx86@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:51>

Django

unread,
Aug 20, 2013, 12:26:17 PM8/20/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by tomasbabej@…):

* cc: tomasbabej@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:52>

Django

unread,
Aug 26, 2013, 8:44:51 AM8/26/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by FunkyBob):

There's no way I'd want to have _only_ a global flag to enable this
behaviour. Certainly, there are cases where I'd rather avoid leading
spaces and blank lines, but equally there are cases where it's important.

Not all the world is HTML. Django templates are frequently used for
content types where the leading whitespace may be important, in the same
projects where it's used for HTML, where it's less important.

Typically to avoid these problems I've started using constructs like:
{{{
<h1>The title</h1>
<ul>{% for item in somelist %}
<li>{{ item }}</li>{% endfor %}
</ul>
}}}

Perhaps not as obvious with the template tags, but clearer with the HTML.

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:53>

Django

unread,
Sep 4, 2013, 6:01:00 PM9/4/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by Semmel):

Just wanted to note that this is exactly the problem I'm facing. Not
everything is HTML and sometimes whitespace matters. The templates for
these cases are very hard to read. :/

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:54>

Django

unread,
Oct 6, 2013, 10:51:44 AM10/6/13
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: new
Type: Bug | Version: master
Component: Template system | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by trbs):

* cc: trbs@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:55>

Django

unread,
Jun 6, 2014, 4:24:32 PM6/6/14
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: closed
Type: Bug | Version: master
Component: Template system | Resolution: wontfix

Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => closed
* resolution: => wontfix


Comment:

As far as I know, the consensus among the core team is that:

- the Django template language is good enough for generating HTML, which
isn't sensitive to whitespace;
- the long term plan is to replace it with a better engine (most likely
Jinja), not to keep working on it;
- if you have more specialized needs (want to generate RTF?) just use
another template engine, there are several to choose from.

Hence, closing wontfix. Thanks everyone who tried contributing to this
ticket, and sorry it didn't happen.

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:56>

Django

unread,
Jun 6, 2014, 10:04:07 PM6/6/14
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: closed
Type: Bug | Version: master
Component: Template system | Resolution: wontfix
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by mrmachine):

Is there an open ticket for tracking the progress of integrating Django's
newly blessed template engine (Jinja)? Or any indication on how "long
term" that plan is? Was there a google groups discussion about this long
term plan?

I did a quick search and couldn't find either. That being the case, it
seems that if no new improvements will be made to Django's template engine
because it might be replaced in the next 5-10 years (seems like a big
job), that's simply leaving everyone who finds the current engine lacking
in any way, stuck in limbo indefinitely.

Is the existing template engine in permanent feature freeze now? Only bug
fixes allowed?

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:57>

Django

unread,
Jun 7, 2014, 3:34:24 AM6/7/14
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: closed
Type: Bug | Version: master
Component: Template system | Resolution: wontfix
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by aaugustin):

Let me restate this with more plainly: we're not interested in this
feature and we don't provide an alternative.

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:58>

Django

unread,
Jul 19, 2014, 1:57:35 AM7/19/14
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> | Status: closed
Type: Bug | Version: master
Component: Template system | Resolution: wontfix
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by anonymous):

I think that what @aaugustin is trying to say is:
Google.com/search?q=how+do+i+use+jinja2+with+django
There, another bug fixed; right?

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:59>

Django

unread,
Apr 15, 2015, 10:39:41 AM4/15/15
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> |
Type: Bug | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by amfarrell):

To achieve this from jinja2, pass both trim_blocks=True and
lstrip_blocks=True when you instantiate either your Environment or
Template.

see: http://jinja.pocoo.org/docs/dev/templates/#whitespace-control

--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:60>

Django

unread,
Oct 19, 2022, 6:36:05 PM10/19/22
to django-...@googlegroups.com
#2594: Template system should handle whitespace better
-------------------------------------+-------------------------------------
Reporter: Gary Wilson | Owner: jshedd
<gary.wilson@…> |
Type: Bug | Status: closed
Component: Template system | Version: dev

Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by adehnert):

* cc: adehnert (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/2594#comment:61>

Reply all
Reply to author
Forward
0 new messages