Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove white space from html source code

Tags:

html

django

I am using django and python. In the template file, I have a drop-down list which is shown as below. It works. The only problem is that there is a lot of white space between in the source html code. Is there any way to remove the white space? Thanks.

           {% for lang_ele in video.languages.all %}               {% ifequal lang_ele.lang display_language  %}                    {% for key, value in language_table.items %}                        {% ifequal lang_ele.lang key%}                          <option selected = "selected" value={{lang_ele.lang}}>{{value}}</option>                        {% endifequal %}                    {% endfor %}               {% else %}                    {% for key, value in language_table.items %}                        {% ifequal lang_ele.lang key%}                          <option value={{lang_ele.lang}}>{{value}}</option>                        {% endifequal %}                    {% endfor %}                {% endifequal %}            {% endfor %} 

The output html souce code looks like this:

<option value=de>German</option>    <option value=el>Greek</option>    <option value=hi>Hindi</option>  
like image 515
susanne Avatar asked Oct 29 '12 15:10

susanne


People also ask

How do I get rid of the white gap in HTML?

HTML. Line Height Property: The CSS line-height-property can be used to set the height of the line, whose value is set to normal, by default. By setting the height of the container at 0%, the white space can be removed.

How do I change white space in HTML?

To create extra spaces before, after, or in-between your text, use the &nbsp; (non-breaking space) extended HTML character.


2 Answers

You can use the spaceless template tag. It:

Removes whitespace between HTML tags.

{% spaceless %} <p>     <a href="foo/">Foo</a> </p> {% endspaceless %} 
like image 173
Timmy O'Mahony Avatar answered Sep 19 '22 20:09

Timmy O'Mahony


  1. Look toward middelware, eg "htmlmin". It processes the file at a time. In addition it has a decorator. https://crate.io/packages/django-htmlmin

  2. gzip will give the same effect. Probably would have cost to opt out of trimming. Look towards django middelware or nginx gzip.

    • django.middleware.gzip.GZipMiddleware
    • http://wiki.nginx.org/HttpGzipModule
  3. You use the controller/model logic in the template. This is wrong way.

like image 25
Serge K. Avatar answered Sep 17 '22 20:09

Serge K.