本文介绍了Django如何通过模板修改数据库记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除我选择的记录,而 run.html 将刷新,我该怎么做?
由于我使用views.py中的函数运行在数据库中发送记录,而运行需要使用运行可以获得的一个参数构建。名称,所以我想我需要通过run.name和run.id,当我点击提交按钮。
I want to delete the records which i select, and run.html will refresh, how can i do that?Since i use function run in views.py to send records in database, and run need one parameter build which can be got by using run.name, so i think i need to pass "run.name" and "run.id" when i click the submit button.
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')
)
run.html
run.html
<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>
views.py
views.py
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来删除所有这些?
i also want to ask if i select multiple record in run.html, whether should i write a forloop in runDelete to delete all of them?
谢谢:D
推荐答案
你一定要看看Django
You should definitely take a look at Django Form
这篇关于Django如何通过模板修改数据库记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!