Opened 11 years ago

Closed 11 years ago

#15798 closed Cleanup/optimization (wontfix)

"spaceless" filter does not not honor <pre> tag formatting

Reported by: dfcode Owned by: nobody
Component: Template system Version: 1.3
Severity: Normal Keywords: spaceless, html, pre
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a blog site where I occasionally wrap some HTML code between <PRE> tags to put it on display for my viewers. I've noticed that when I apply the {% spaceless %} filter to my document, Django plows straight through the embedded HTML code with no regard for the "pre-formatted" declaration. An example might be:

      <label>This is an example of some code I want to display in indented form.</label>
      <input type="submit" />

results in:

<html><body><pre><form><label>This is an example of some code I want to display in indented form.</label><input type="submit" /></form></pre></body></html>

and one line of code is displayed on my webpage.

Perhaps this is intentional. If not, I think the 'spaceless' filter should be programmed to recognize <pre> tags and leave the content within them alone.

Change History (1)

comment:1 Changed 11 years ago by Aymeric Augustin

Easy pickings: unset
Resolution: wontfix
Status: newclosed

Currently the {% spaceless %} tag does what is documented: it removes all spaces.

#8123 discusses customizing its behavior for certain tags (inline vs. block); it was rejected by two core developers. The bottom line is that if you do not want to remove all spaces, you just shouldn't use {% spaceless %}.

In my opinion, the behavior is intentional, so I will close the ticket as wontfix.

PS1 : your idea was briefly mentioned here: but not discussed further.

PS2 : for the record, here is the history of the {% spaceless %} tag:

Note: See TracTickets for help on using tickets.
Back to Top