gpt4 book ai didi

django - request.POST.getlist 在 Django 中返回 None 列表?

转载 作者:行者123 更新时间:2023-12-02 05:16:01 24 4
gpt4 key购买 nike

我有一个像这样的 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>

结果变量生成自:

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))

最佳答案

在选择后包含 [],因为您正在获取数组表单请求

choices = request.POST.getlist('choice[]')

这将解决您的问题

关于django - request.POST.getlist 在 Django 中返回 None 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14334318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com