如何在静态java脚本中显示我的管理面板问题



这是我在静态文件夹中的js文件:

let questions = [
{
question :"my question",

choiceA : "Correct",
choiceB : "Wrong",
choiceC : "Wrong",
correct : "B"
}

这是管理员.py

from django.contrib import admin
from .models import Question
admin.site.register(Question)

这是型号.py

class Question(models.Model):

name=models.CharField(max_length=300)

views.py

def quiz(request):
question=Question.objects.all()
return render(request,"index.html",{"question":question})

这个问题是应该在js文件中写什么来代替";我的问题"?

index.html

<script>
{% for question in questions %}
let question = {}
question["name"] = problem.name
questions.push(question)
{% endfor %}
</script>

views.py中,为了增加可读性,更改

{"question": question} to {"questions": question}

注意";s";在";问题";。这提高了for循环的可读性

最新更新