The newlines aren't useful and they break assertions like this:
<option value="USD" selected>US Dollar</option> in form.as_p
--- end report---
git
has the warning \ No newline at end of file
and Github has a warning symbol for the missing newline."{% include %}
could do .rstrip('\n')
on whatever it renders.Preston pointed out that Jinja2 does something similar:
http://jinja.pocoo.org/docs/dev/templates/#whitespace-control
We could add a new option to {% include %}
, though." Adam also said, "I too have used DTL for text emails that would break under that behaviour. New option to include
sounds good to me."
Me again: In the long run, having {% include %} remove the trailing newline seems like a more sensible default. For example, I wouldn't expect this code to have a newline inserted between it:
{% include "foo.txt" %}
{% include "bar.txt" %}
An option for {% include %}
seems superfluous given that if you were writing
{% include "foo.txt" %}{% include "bar.txt" %}
now you can write the first thing which is much more intuitive.
How about a keep_trailing_newline
TEMPLATES option for backwards compatibility for those who don't want to adapt their templates for the new behavior? Jinja2 has that option.
{% include %}
, though it doesn't allow us to ensure that we strip the newline in the specific case of attrs.How we default the engine option I guess just depends on how seriously we take backwards compatibility. If we default it to strip and make people add the config to preserve the old behavior, that's not really backwards compatible. Historically (as seen in Malcolm's comment) we would choose to err on the side of actual backwards compatibility in a case like this, even if it didn't result in the ideal future behavior. But the adaptation isn't hard in this case, so I won't object if the choice is to break back-compat.
If it's not a per-include choice, of course, we have to break overall back-compat to preserve form-attr-rendering back-compat.
------
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8124d314-eb26-4465-9fc8-5b04fe2ba618%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
eep_trailing_newline
option? If we don't enable it for existing projects, then forms will render with extra newlines. I think it's better to have projects opt-out of the behavior if they're unable to audit their non-HTML templates due to time constraints. Only enabling it for new projects means that the tests for projects like django-money will break until the option is enabled. I consider the keep_trailing_newline
option a temporary backwards compatibility measure and would like to eventually remove it.--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/de92a16a-25c7-439a-95a1-3a2b43a6c1ac%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8124d314-eb26-4465-9fc8-5b04fe2ba618%40googlegroups.com.
Whitespace control in templates is an exercise in frustration. In my experience more flexible tools such as {%-, {%+, -%}, and +%} in Jinja2 increase the frustration.
I'd like to know from Carl, Adam, and others, how much effort would be required to adapt the templates in your project for the new behavior. I imagine a script could be written to add newlines after all {% include %} in all plain text templates, for example.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/980cf18c-20e2-411a-9536-acea1e4d3556%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/980cf18c-20e2-411a-9536-acea1e4d3556%40googlegroups.com.
--Adam
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d3390e72-7dc4-44bb-bac1-3546ad894cf1%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/980cf18c-20e2-411a-9536-acea1e4d3556%40googlegroups.com.
I'd like to merge the current patch that removes the trailing newline in the attrs.html template, then revisit the issue of {% include %} stripping the trailing newline for the next version of Django so we don't need to rush a decision about that.