Snippet List
Tightens up response content by removed superflous line breaks and whitespace.
By Doug Van Horn
---- CHANGES ----
v1.1 - 31st May 2011
Cal Leeming [Simplicity Media Ltd]
Modified regex to strip leading/trailing white space from every line, not just those with blank \n.
---- TODO ----
* Ensure whitespace isn't stripped from within <pre> or <code> or <textarea> tags.
- middleware
- strip
- whitespace
Here is a class decorator that allows not to bother with stripping leading and trailing white space from user input provided via forms. This could be a temporary solution for an issue addressed in the ticket [#6362](http://code.djangoproject.com/ticket/6362).
The documentation is provided in the form of doctest. The decorator works with `ModelForm`'s just as well as with ordinary forms.
Note however that this is not a 100% panacea. Your models still could become malformed if theirs data is obtained from another source, not forms.
- newforms
- forms
- strip
- auto
When writing clean and easy-to-read templates, it's usually good to have structural template tags (e.g. {%for%}, {%if%}) alone on their own line with proper indentation.
When such a template is rendered, the resulting HTML will have blank lines in place of the template tags. The leading blank space used for indentation is also intact.
This template tag strips all empty and all-whitespace lines when rendering the template. Be careful not to apply it when not intended, e.g. when empty lines are wanted inside PRE tags.
- template
- html
- strip
- empty
- blank
4 snippets posted so far.