Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将BooleanField从模型引用到模板_Python_Templates_View_Model_Boolean - Fatal编程技术网

Python 如何将BooleanField从模型引用到模板

Python 如何将BooleanField从模型引用到模板,python,templates,view,model,boolean,Python,Templates,View,Model,Boolean,请帮忙 我制作了两种型号:问答式: 徖 from django.db import models from django.utils import timezone class Question(models.Model): question_text = models.CharField(max_length=400) time_pub = models.DateTimeField() class Answer(models.Model): question_Answe

请帮忙

我制作了两种型号:问答式:

from django.db import models
from django.utils import timezone
class Question(models.Model):
    question_text = models.CharField(max_length=400)
    time_pub = models.DateTimeField()
class Answer(models.Model):
    question_Answer = models.ForeignKey(Question, on_delete= models.CASCADE)
    answer_text = models.CharField(max_length=100)
    true_answer = models.BooleanField(default = False)
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
import random
# Create your views here.

def index(request):
    bocauhoi = Question.objects.all()
    rand = random.choice(bocauhoi)
    traloi = rand.answer_set.all()

    return render(request,"Piapp/index.html",{"random":rand,"tl":traloi})

def Result(request):
    kqua =Answer.true_answer()
    return render(request,"Piapp/result.html",{"kq":kqua})
和my Views.py如下:

from django.db import models
from django.utils import timezone
class Question(models.Model):
    question_text = models.CharField(max_length=400)
    time_pub = models.DateTimeField()
class Answer(models.Model):
    question_Answer = models.ForeignKey(Question, on_delete= models.CASCADE)
    answer_text = models.CharField(max_length=100)
    true_answer = models.BooleanField(default = False)
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
import random
# Create your views here.

def index(request):
    bocauhoi = Question.objects.all()
    rand = random.choice(bocauhoi)
    traloi = rand.answer_set.all()

    return render(request,"Piapp/index.html",{"random":rand,"tl":traloi})

def Result(request):
    kqua =Answer.true_answer()
    return render(request,"Piapp/result.html",{"kq":kqua})

from django.db import models
from django.utils import timezone
class Question(models.Model):
    question_text = models.CharField(max_length=400)
    time_pub = models.DateTimeField()
class Answer(models.Model):
    question_Answer = models.ForeignKey(Question, on_delete= models.CASCADE)
    answer_text = models.CharField(max_length=100)
    true_answer = models.BooleanField(default = False)
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
import random
# Create your views here.

def index(request):
    bocauhoi = Question.objects.all()
    rand = random.choice(bocauhoi)
    traloi = rand.answer_set.all()

    return render(request,"Piapp/index.html",{"random":rand,"tl":traloi})

def Result(request):
    kqua =Answer.true_answer()
    return render(request,"Piapp/result.html",{"kq":kqua})
我想检查字段:true\u回答并在新模板中打印。 如何处理:如果为真,则模板中的“您的答案为真”和“您的答案为错”。 请帮忙