我想删除我选择的记录, run.html 会刷新,我该怎么做? 由于我在views.py中使用函数运行来发送数据库中的记录,而运行需要一个参数构建,可以使用 run.name ,所以我想当我点击提交按钮时我需要传递“run.name”和“run.id”。
urlpatterns = patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
(r'^home/$', 'views.home'),
(r'^home/(?P<build>[^/]+)/$', 'views.run'),
(r'^run/delete/$', 'views.runDelete')
)
<form name="form" method="post" action="/run/delete">
<input type="submit" value="Delete" style="margin-left:149px; width:80px; height:30px">
<table border="1"; borderColor=black>
<td></td>
<td><b>Run</b></td>
{% for run in run_list %}
<tr>
<td><input type="checkbox" name="var_delete" value="{{run.id}}"></td>
<td>{{run.name}}</td>
</tr>
{% endfor %}
</table>
</form>
def run(request, build):
run_list = TestRun.objects.all().order_by('id')
return render_to_response('run.html', {'run_list': run_list})
def runDelete(request, id, build):
TestRun.objects.get(id=id).delete()
run()
我还想询问我是否在 run.html 中选择多条记录,是否应该在runDelete中写一个forloop来删除所有记录?
谢谢:D