我在视图中有以下代码:
def submit_affective(request):
if request.method == 'POST':
choice=request.POST['aff_choices']
urlid=request.POST['url_list']
url = Url.objects.get(id=urlid)
aff_result=Affective.objects.create(
affective=choice, url=url
)
return redirect('detail_affective',id=url.id)
def detail_affective(request,id):
boring_count=Affective.objects.filter(affective='Boring',url.id=id).count()
confusing_count=Affective.objects.filter(affective='Confusing',url.id=id).count()
engaging_count=Affective.objects.filter(affective='Engaging',url.id=id).count()
context = {
'boring_count':boring_count,
'confusing_count':confusing_count,
'engaging_count':engaging_count,
}
return render(request,'feedback/detail_affective.html',context)
我只想显示detail_affective
中的“无聊”、“困惑”、“参与”的数量,该URL已在submit_affective
中提交选择。请告诉我代码中的问题。我是否正确地将url id传递给详细信息?我的过滤方法正确吗
不能使用
url.id
表达式作为筛选参数,只需使用url_id
:您还需要将
id
作为url参数添加到urlpattern中:相关问题 更多 >
编程相关推荐