开发者

How to use a Django include tag for a separate HTML template?

I am trying to use the include Django template tag, and inside it I reference a template which handles the format of the form. When I reference this though inside my template it outputs each of the dynamic parts, each character per new line, it is really strange. For example here is a snippet of the output:

<form action="/admin/events/create_submit/" method="post">

    <div class="fieldWrapper">

        : &lt;
    </div>

    <div class="fieldWrapper">

        : l
    </div>

    <div class="fieldWrapper">


        : i
    </div>

    <div class="fieldWrapper">

        : &gt;
    </div>

...

EXPECTED OUTPUT

<form action="/admin/events/create_submit/" method="post">

        <div class="fieldWrapper">
           <li><label>field</label><input type="text" /></li>
        </div>

...

I realise the markup on the li inside the div is incorrect but I am trying to understand why the html is being encoded and each character split into a new line inside the template div and prefixed with the colon ":"

The template which I am trying to render is this:

<form action="{{action}}" method="post">
{% for field in form %}
    &l开发者_C百科t;div class="fieldWrapper">
        {{ field.errors }}
        {{ field.label_tag }}: {{ field }}
    </div>
{% endfor %}
    <p><input type="submit" value="Submit" /></p>
</form>

And I reference the include template like this:

{% include "forms/form_template.html" %}

Does anyone know or could help m as to why this would be causing each dynamic piece to output per character on each line?

TIA

Andrew


form is probably a string rather than a Form object, and iterating over a string yields its individual characters.


spaceless tag

Removes whitespace between HTML tags. This includes tab characters and newlines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜