我已经尝试了很多,但是我一次只能显示一个问题 测验应用程序django。
这是html文件的正文
<form id="myform" action="/javar/" method="post">
{% csrf_token %}
<center><h1 class ="hone">Welcome {{user.username}}, To Online Quiz</h1></center>
{% for item in query_results %}
<div class="question-panel">
<div class="question" >
<label class="question-label">{{ item.QUESTION_NO }}</label>
<b>{{ item.QUESTION }}</b>
</div>
<ol class ="op" type='A'>
<li ><input type='radio' name="java{{item.QUESTION_NO}}"
value='1' />{{item.OPTION1}}<br><br></li>
<li ><input type='radio' name="java{{item.QUESTION_NO}}" value='2' />{{item.OPTION2}}<br><br></li>
<li ><input type='radio' name="java{{item.QUESTION_NO}}"
value='3' />{{item.OPTION3}}<br><br></li>
<li ><input type='radio' name="java{{item.QUESTION_NO}}" value='4' />{{item.OPTION4}}<br><br></li>
</ol>
<hr/>
</div>
<center><input type="submit" value="Submit" onclick="return
ValidateForm(this.form)"></center>
</form>
这里是models.py
class JAVATEST(models.Model):
QUESTION_NO=models.IntegerField(default=0)
QUESTION=models.CharField(max_length=300)
OPTION1=models.CharField(max_length=300)
OPTION2=models.CharField(max_length=300)
OPTION3=models.CharField(max_length=300)
OPTION4=models.CharField(max_length=300)
ANSWER=models.IntegerField(default=0)
def __str__(self):
return str(self.QUESTION_NO)+" "+self.QUESTION+" "+self.OPTION1+"
"+self.OPTION2+" "+self.OPTION3+" "+self.OPTION4+" "+str(self.ANSWER)
这是views.py
def javaq(request):
context = {
'query_results' : JAVATEST.objects.all()
}
return render(request, 'javaq.html',context)
def javar(request):
if request.method=="POST":
chosenOption = ''
correctAns = ''
c=0
x=1
for ans in JAVATEST.objects.all():
chosenOption=str(request.POST.get("java"+str(x)))
correctAns=str(ans.ANSWER)
if chosenOption==correctAns:
c=c+1
x=x+1
article = result()
article.sid = request.session['sd']
article.marks = c
article.subject = 'JAVA'
article.tdate = str(datetime.datetime.now())
article.save()
context = {
'query_results1' :c
}
return render(request, 'javar.html',context)
请帮助我,因为我一次无法显示单个问题
答案 0 :(得分:0)
您将从此处将所有JAVATEST实例提供给模板
library(shiny)
library(magrittr)
library(dplyr)
ui <- uiOutput("myUI")
server <- function(input, output, session) {
output$myUI<-renderUI({
fluidPage(
selectInput("cyl","cyl",unique(mtcars$cyl)),
selectInput("mpg","mpg",mpg()))
})
mpg<- reactive({
if(!is.null(input$cyl))
unique(mtcars%>%dplyr::filter(cyl==input$cyl)%>%select(mpg))
})
}
shinyApp(ui = ui, server = server)
为什么不只是一个问题?可能会跟踪用户参加的问题,并且一次排除用户参加的问题。
def javaq(request):
context = {
'query_results' : JAVATEST.objects.all() # <----
}
return render(request, 'javaq.html',context)