Javascript 以10为基数的int()的文本无效:'';德扬戈
template.htmlJavascript 以10为基数的int()的文本无效:'';德扬戈,javascript,python,django,django-models,django-templates,Javascript,Python,Django,Django Models,Django Templates,template.html <tr id="head-{{ report_person.report_person.id}}"> <td style="width:150px;"><input type="button" name="delete" class="delete_icon" value="{{ report_person.report_person.id}}"/> {{report_person.report_person.name
<tr id="head-{{ report_person.report_person.id}}">
<td style="width:150px;"><input type="button" name="delete" class="delete_icon" value="{{ report_person.report_person.id}}"/>
{{report_person.report_person.name }}</td>
<td> {{report_person.info.first_aid}}{{report_person.info.first_aid.label}}</td>
<td>{{report_person.info.sick_bay}}{{report_person.info.sick_bay.label}}</td></tr>
views.py
def method(request):
if request.method == 'POST':
form = ReportPersonForm(request.POST)
if 'delete_id' in request.POST: #To delete added names
ReportPerson.objects.filter(id=request.POST['delete_id']).delete()
Actions.objects.filter(id=request.POST['delete_id']).delete()
InjuredLocation.objects.filter(id=request.POST['delete_id']).delete()
return render
自定义确认弹出窗口以删除添加的数据
<div class="delete_confirm" style="display:none">
<form method="post" action="." id="{{ report_person.report_person.id}}">
{% csrf_token %}
<h2> Are you sure</h2>
<br />
<div style="width:180px;float:right;margin:20px 5px 0 10px">
<button type="button" name="delete" class="delete_icon1" value="{{ report_person.report_person.id}}" />Delete</button>
<button style="margin-right:10px;" type="button" class="close" name="cancel" class="forward backicon">
<img src="{{ STATIC_URL }}images/button-icon-ir-back.png" width="12" height="17" alt="" />
Cancel</button>
</div>
</form>
</div>
以前,我通过单击delete_图标实现了删除功能,它工作正常。现在,我在删除之前添加了一个删除确认弹出框。弹出框正在显示,但在单击删除按钮时,我无法删除。value=“{{report_person.report_person.id}”
未传入要删除的id弹出框。如果单击“删除”,则会出现此错误
"ValueError at /report/who/
invalid literal for int() with base 10: ''"
在FF控制台中。我想知道如何将id(value=“{{{report\u person.report\u person.id}}”)从html传递到模板。可以通过视图中的request.POST.get('delete')
获得“删除”按钮的值。如果希望将该值捕获为URL段,则需要将其作为表单的action
参数的一部分,或在Ajax方法的URL
参数中传递(可能来自表单)。@Brandon我想使用自定义弹出框执行删除操作,你能在这里指导我如何在我的应用程序中进行操作吗?我需要查看你的URL模式和视图,以便为你提供更多建议。我更新了我的模板views.py和URL.py。行的表是动态创建的,行的id是id=“head-{{report\u person.report\u person.id}”中提到了delete的id。当您:console.log(var id=$(this.attr('value'))时会得到什么代码>?,顺便说一句,您可以将其编写为:$(this).val();
$('.delete_icon1').click(function() {
var csrf_token = $("#csrf_token").val();
var id = $(this).attr('value');
$.ajax({ // create an AJAX call...
data:{
csrfmiddlewaretoken: csrf_token,
delete_id:id
},
type:'POST',
url: '/report/who/', // the file to call
cache:false,
success: function() { // on success..
window.location.href = window.location;
}
});
return false;
});
"ValueError at /report/who/
invalid literal for int() with base 10: ''"