在def中列出了一个表中的文章,其中包含我的模型表单的inputtext,RequestEditForm,每篇文章旁边的输入,以及一个保存inpuText保存量的按钮。我的问题是该按钮什么都不做,因此它不会在数据库中保存输入的数量。
def ListAll(request, id_especialidad):
especialidad = Especialidad.objects.get(id=id_especialidad)
if request.method == 'GET':
user = request.user
if user.is_superuser:
pedido = Pedido.objects.filter(especialidad=especialidad)
form = PedidoEditForm()
if form.is_valid():
form.save()
pedido.estado = 'pendiente'
pedido.fecha_pedido = datetime.now()
pedido.save()
return render(request,'admindata.html',locals(),{'form':form})
<section id="contenido">
<div class="container" style="margin:50px auto width="100%"">
<form id="myform" method="post">
<table id="example" class="table table-border table-striped table-hover">
<thead>
<tr>
<td>Servicio</td>
<td>Cod experto</td>
<td>Nombre</td>
<td>stock</td>
<td>Cantidad</td>
<td>Fecha Pedido</td>
<td>Estado</td>
<td>Ingresar</td>
<td></td>
</tr>
</thead>
<tfoot>
<tr>
<td>Servicio</td>
<td>Cod experto</td>
<td>Nombre</td>
<td>stock</td>
<td>Cantidad</td>
<td>Fecha Pedido</td>
<td>Estado</td>
<td></td>
</tr>
</tfoot>
<tbody>
{% if pedido %}
{% for ped in pedido %}
<tr>
<td>{{ ped.especialidad.nombre }}</td>
<td>{{ ped.articulo.cod_experto }}</td>
<td>{{ ped.articulo.nombre }}</td>
<td>{{ ped.articulo.stock }}</td>
<td>{{ ped.cantidad }}</td>
<td>{{ ped.fecha_pedido }}</td>
<td>{{ ped.estado }}</td>
<td>{% csrf_token %}
{{form.as_p}}</td>
<td></td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
</form>
</div>
</section>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
<script src="{% static "js/jquery.dataTables.min.js" %}"></script>
<script src="{% static "js/dataTables.bootstrap.min.js" %}"></script>
<script src="{% static "js/dataTables.checkboxes.min.js" %}"></script>
<script src="{% static "js/jquery.form.min.js" %}"></script>
<script>
$(document).ready(function (){
var table = $('#example').DataTable({
'columnDefs': [
{
'targets': 0,
}
],
});
table.column(7).every( function () {
var column = this;
var select = $('<input type="submit" form="myform" class= "btn btn- success" value="Guardar">')
.appendTo($(column.footer()).empty())
.on('change', function() {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function(d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
});
因为按钮不起作用,我也缺乏,我有以下错误: 用户警告:
A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.
" A {% csrf_token %} was used in a template, but the context " help me pls!
答案 0 :(得分:0)
而不是render_to_respoonse
使用render
这样:
return render(request, template, locals())
此外,您在表单外还有一个submit
按钮!
您应该将其放在<form></form>
内,或者在<input>
id of the form where it belongs中定义。像这样:
<input type="submit" form="myform" class= "btn btn-success" value="Guardar">