我有一个这样的html模板:
<table border="1" align="center">
{% for result in result %}
<tr>
<td><input type="checkbox" name="choice" id="choice{{ forloop.counter }}" value="{{ choice }}" /></td>
<td><label for="choice{{ forloop.counter }}">{{ choice }}</label><br /></td>
<td>{{ result.file_name }}</td>
<td>{{ result.type }}</td>
<td>{{ result.size }}</td>
<td>{{ result.end_date }}</td>
<td>{{ result.source }}</td>
{% endfor %}
</tr>
</table>
{{ c }}
<h4><a href="/delete_files/">Delete File</a></h4>
result variable
生成自:
def uploaded_files(request):
log_id = request.user.id
b = File.objects.filter(users_id=log_id, flag='F') #Get the user id from session .delete() to use delete
return render_to_response('upload.html', {'result': b}, context_instance=RequestContext(request))
这是我尝试从模板中选择值的地方:
def delete_files(request):
log_id = request.user.id
choices = request.POST.getlist('choice') #Get the file name from the as a list
for i in choices:
File.objects.filter(users_id=log_id, file_name=i).update(flag='D')
return render_to_response('upload.html', {'c': choices}, context_instance=RequestContext(request))