我可以在我的 form.cleaned_data 中使用什么来查询数据库?
what can i use form.cleaned_data in my to query a database?
form.cleaned_data['question']
包含字符串 "do you like soccer"
问题模型的问题字段中也有 'do you like soccer'
x = QuestionModel.objects.get(question= form.cleaned_data['question'])
为什么会报错"QuestionModel matching query does not exist."
为什么会失败?
您也可以尝试获取变量中的值,然后传递给查询集。
que = form.cleaned_data['question']
x = QuestionModel.objects.get(question=que)
这是更好的方法。
form.cleaned_data['question']
包含字符串 "do you like soccer"
问题模型的问题字段中也有 'do you like soccer'
x = QuestionModel.objects.get(question= form.cleaned_data['question'])
为什么会报错"QuestionModel matching query does not exist."
为什么会失败?
您也可以尝试获取变量中的值,然后传递给查询集。
que = form.cleaned_data['question']
x = QuestionModel.objects.get(question=que)
这是更好的方法。