python - 我尝试在 django 中构建的测验 - 如何使其工作?
问题描述
我正在构建一个练习希伯来语-英语单词的测验。每次计算机从数据库中提取 4 个单词 rednomiles 并且用户从单词中选择适当的单词。总是从 request.post.get = None 开始的问题。并且缩进是在 None 前面进行的,这意味着即使答案正确,结果也不正确。我该如何解决?
事实上,甚至在用户做出选择之前就已经进行了比较。而且选择后得到的结果通常是错误的。
例如-在第一轮(正确的工作和下一轮将是y)计算机选择x-现在我单击x结果=不正确的x!= y..
下一轮计算机选择 y ,现在我点击 y (正确的工作和下一轮将是 z) 结果 = 不正确的 y != z..
def practice(request):
words_list = Words.objects.filter(approved= True) # Take all the words that approved by the admin
four_options = [random.choice(words_list) for i in range(4)]
x = four_options[0]
z = x.Hebrew_word
random.shuffle(four_options)
word = z[:4]
choice_user = request.POST.get("quiz")
choice_1 = str(choice_user)
choice = choice_1[:4]
if request.method == "POST":
if choice == word:
message = f'Correct {choice} == {word}'
return render(request, "practice.html",
{"four_options": four_options, "x": x, "z": z, "choice": choice, 'word': word,"message":message})
if choice != word:
message = f'Incorrect {choice} != {word}'
return render(request, "practice.html",
{"four_options": four_options, "x": x, "z": z, "choice": choice, 'word': word,"message":message})
return render(request, "practice.html", {"four_options": four_options, "z": z, "x": x,"choice":choice ,'word':word})
<div id="word"> {{x.English_word}}</div>
{%for i in four_options%}
<form method="POST">
{%csrf_token%}
<br/>
<input name = "quiz" type="submit" value={{i.Hebrew_word}} class="btn btn-primary"/>
</form>
{%endfor%}
{{message}}
解决方案
推荐阅读
- java - 如何在 IDEA 中使用命令参数调试 Java?
- javascript - JavaScript - 在 N 个字符后截断 innerHTML 字符串,并去除其中的任何标签或 arrtibute
- ios - SwiftUI 中 NavigationView 内的全局导航链接
- python - 从 XHR 响应中展平 Python 中的 json
- python - QGraphicsItem在改变孩子时不改变父母的笔
- json - 仅从以下 JSON 中提取状态为在线的服务器名称。使用 jq 1.5 版
- c++ - mpz_set_str 将其分配给数字后输出 0
- javascript - 此 Web3.js 调用没有结果
- react-native - 将 curl 语句更改为 axios
- python - Pandas Plot,从高到低排列条形图,并分别为各个条形图着色