Is there a way to supress blank lines in the HTML?

60 views
Skip to first unread message

Daniel Grace

unread,
Oct 22, 2014, 7:24:16 PM10/22/14
to django...@googlegroups.com
Hi,
Is there a way to suppress blank lines in the HTML?
I tried using the spaceless tag but it is overkill for what I want.
I just want to suppress the blank lines from the HTML and not all space.

Any ideas?

Thanks

termopro

unread,
Oct 23, 2014, 2:59:35 AM10/23/14
to django...@googlegroups.com

May i ask you why do you need that ?

If you need this for some performance reasons like html compression, you are doing it wrong.
Instead you could use server-side GZIP compression when serving html which will do the job much more efficiently.

If you are concerned about the structure of the document, the "beauty" of indents and spaces - i guess you should google for "html prettify for python".

Best regards,
Vladimir

Avraham Serour

unread,
Oct 23, 2014, 4:30:07 AM10/23/14
to django...@googlegroups.com
I suggest taking a look at google pagespeed, you can add it to nginx or even apache
But many people like to do this at the django level, you should look for apps like django compressor

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ec0ca154-f465-4970-b8c4-9b92140a07c5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jon Dufresne

unread,
Oct 24, 2014, 10:30:25 AM10/24/14
to django...@googlegroups.com
> If you need this for some performance reasons like html compression, you are doing it wrong.
> Instead you could use server-side GZIP compression when serving html which will do the job much more efficiently.

Just a heads up. Compressing dynamic responses over HTTPS is
considered insecure due to the BREACH attack.
<http://en.wikipedia.org/wiki/BREACH_%28security_exploit%29>

Django documentation also contains a blurb about this:
<https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip>

I don't know the specifics here, but the issue is relevant.

Cheers,
Jon

Daniel Grace

unread,
Oct 24, 2014, 11:35:50 AM10/24/14
to django...@googlegroups.com
Thanks people for the info.  I was looking for a way to beautify the code, rather than for performance / compression.  In particular I came across this when I implemented a template tag which, under certain circumstances returns an empty string.  This works well but causes blank lines in the code, if they are present in the original template.  I did find the almostspaceless template tag on http://kuttler.eu/code/django-almost-spaceless-template-tag/ but I could not get it to work, as I don't know where "re.sub" comes from.

Jon Dufresne

unread,
Oct 24, 2014, 11:44:04 AM10/24/14
to django...@googlegroups.com
Try adding "import re" to the top to import the Python re module.
<https://docs.python.org/3.5/library/re.html>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d4875909-54b2-4655-b459-c71c4bb7efc9%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages