1.编辑views.py,加入edit_server()函数
def edit_server(request, eid):
sid = int(eid) edit_svr = machine.objects.get(id=sid) if request.method == ‘POST‘: edit_form = ServerForm(request.POST, instance=edit_svr) if edit_form.is_valid(): edit_form.save() return HttpResponseRedirect(‘/server/assets‘) else: edit_form = ServerForm(instance=edit_svr) return render_to_response(‘edit.html‘, {‘edit_form‘: edit_form, ‘sid‘: sid})
2.编辑urls.py,加入如下语句:
url(r‘^edit/(?P<eid>\d+)/$‘, ‘server.views.edit_server‘),
3.edit.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Edit</title>
<script LANGUAGE="JavaScript">
function del(){
if(window.confirm("确实要删除吗?")){
window.location ="/server/del/";
}else{
return;
}
}
</script>
</head>
<body>
<form action="" method="post">
{{ edit_form.as_p }}
<input type="submit" value="保存">
</form>
</body>
</html>
时间: 2024-10-07 22:52:39