pyth0ner
pyth0ner

Reputation: 181

How to Remove Newline symbols Produced by some Field of Django Custom Form in Template?

Custom Form:

CALLMODE_CHOICES = ( 
    (1,'a'), 
    (2,'b'), 
    (3,'c'), 
) 
class EcmNoneTelForm(forms.Form): 
    callmode = forms.ChoiceField(choices=CALLMODE_CHOICES, required=False) 

Template:

{{form.callmode}}

Each line has newline:

<select name="callmode" id="id_callmode"> 
<option value="1">a</option> 
<option value="2">b</option> 
<option value="3">c</option> 
</select>

I wanna all content to be displayed in a row, because I wanna combine {{form.callmode}} with some other string in js script:

var str = "<form>" + "{{form.callmode}}" + "</form>";

Upvotes: 2

Views: 1702

Answers (1)

K Z
K Z

Reputation: 30453

Assuming you meant you want the generated HTML to have no newline, I think you can do that with the spaceless template tag:

{% spaceless %}
    <p>
        <a href="foo/">Foo</a>
    </p>
{% endspaceless %}

This example would return this HTML:

<p><a href="foo/">Foo</a></p>

Upvotes: 3

Related Questions