I created a ticket:
http://code.djangoproject.com/ticket/2594
I also attached a patch that I have done a little testing with and
seems to work ok. I first attacked this at the Node level, but
realized that might not be the best way because the Nodes get rendered
recursively. In order to clean up the line's whitespace, you would
have to wait for everything to render and then remember which
lines/templatetags/templatevariables the render originated from.
The patch attacks the problem at the token level. It finds the end of
lines and then evaluates each line to determine if whitespace should be
cleaned up. But the patch is not perfect. If you have lines in your
template like:
{% for item in items %}<li>{{ item.name }}</li>{% endfor %}
or
{% if item.name %}<li>{{ item.name }}</li>{% endif %}
where blocks are on the same line as text and the block renders no
output, my patch is fooled and still will insert a blank line in the
rendered string.
If, however, you were to instead write the above examples as:
{% for item in fooitems %}
<li>{{ item.name }}</li>
{% endfor %}
or
{% if item.name %}
<li>{{ item.name }}</li>
{% endif %}
then my patch will clean up the whitespace nicely. This patch may also
very well not work on windows due to the different line endings.
There are a few setbacks though. It seems that with this patch,
render_to_string becomes 2-3 times slower. Toying with python's
profile for a few minutes shows that most of the time was being spent
in Token.__init__ and Node.__init__, which seemed logical due to all
the extra tokens, and hence nodes, that get created when using my patch.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---