django form label in {% for %} statement -
i want wrap in label, when template rendered, didn't generate right html, here code:
{% item in studentinfo %} <form action="" method=""> {% csrf_token %} <tr> <td>{{ item.nickname|default_if_none:"" }}</td> <td>{{ item.mobile|default_if_none:"" }}</td> <td>{{ item.register_at|date:"y-m-d"|default_if_none:"" }}</td> <td>{{ item.sales.first_name|default_if_none:"" }}</td> <td><strong class="red-text">{{ item.price|default_if_none:"" }}</strong></td> <td><strong class="red-text">{{ item.remaining|default_if_none:"" }}</strong></td> <td>{{ item.level|default_if_none:"" }}</td> <td> {% if item.state %} {{ setstudentform.state|default:item.state }} {% else %} {{ setstudentform.state }} {% endif %} </td> <td>{{ item.source|default_if_none:"" }}</td> <td> {% if item.feature %} {{ setstudentform.feature|default:item.feature }} {% else %} {{ setstudentform.feature }} {% endif %} </td> </tr> </form> {% endfor %}
but it's generated html this:
<form method="" action=""></form> <input type="hidden" value="8n1o4oks4mmgn1ujanmzx0o2x5xgumny" name="csrfmiddlewaretoken">
with nothing inside <form>
, why that
you want this:
<form method="post"> {% csrf_token %} <table> {% item in studentinfo %} <tr> <td>...</td> </tr> {% endfor %} </table> </form>
the way template structured not valid html.
also, don't need this:
{% if item.feature %} {{ setstudentform.feature|default:item.feature }} {% else %} {{ setstudentform.feature }} {% endif %}
simply {{ setstudentform.feature|default:item.feature }}
intend.
Comments
Post a Comment