[Answered ]-Django template – p tag is closed for no reason

2👍

HTML does not permit block elements like ul inside p elements. So when your field has an error, which is rendered with a ul, your browser helpfully closes the p to make it valid. (What you’re looking at is the browser’s DOM representation, not the actual rendered HTML which won’t contain the magic close elements: do “view source” to see this.)

You should move the error tag out of the p. If you like, you can wrap the whole thing in something like a div.

0👍

It looks like you didn’t initialize your form in the html.
See the following example:

<form method="post" action="." enctype="multipart/form-data">
    {% csrf_token %}
    {% for field in my_form %}
    <p>{{ field.label_tag }} {{ field }}</p>
    {% endfor %}
    <input type="submit" value="Submit Form" />
</form>

Leave a comment