使用Django 1.8模板,尝试POST表数据。我设置<TABLE> id = 'tasktable'
。但是在请求信息中,没有任何数据&#39;
此外,如何在Django视图中访问动态表POST数据?
只有这样才能成为每一行的身份吗?
(例如<td><input id='1_data'></td><td><input id='2_data'></td>
代码下方是模板。
{% extends "base.html" %}
{% load staticfiles %}
{% block scripts %}
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$(function () {
$('#btn-add-row').click( function() {
$('#tasktable > tbody:last').append('<tr><td><input type="text"></td><td><select name="format"><option value="INT">INT</option><option value="TEXT">TEXT</option></select></td></tr>');
});
$('#btn-delete-row').click( function() {
$('#tasktable > tbody:last > tr:last').remove();
});
});
</script>
{% endblock %}
{% block title %}
Angel Feeder - Manager
{% endblock %}
{% block body %}
<div class="container">
<form class="" method="post" action="">
{% csrf_token %}
{{ taskform }}
<br>
<button id="btn-add-row" type="button">+</button><button id="btn-delete-row" type="button">-</button>
<table name='tasktable' id='tasktable' class="table">
<thead>
<tr>
<th>Data name</th>
<th>Format</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text"></td>
<td><select name="format"><option value="INT">INT</option><option value="TEXT">TEXT</option></select></td>
</tr>
</tbody>
</table>
<button class="btn btn-lg btn-primary" type="submit">set task</button>
</form>
</div>
{% endblock %}
答案 0 :(得分:0)
Only form elements with a name
attribute will have their values passed when submitting a form.
name
is not an allowed attribute of <table>
in HTML5
https://stackoverflow.com/a/13677670/3033586
显然,您必须为name
中的每个表单元素设置唯一的table>tr>td
,以便在post
之后引用它
如果你想要简单的样式[模型]表单(例如使用bootstrap) - 请查看http://django-crispy-forms.readthedocs.org/en/latest/