Не удалось разобрать остаток: '% if survey.questiontype1 == multiplechoice %' из '% if survey.questiontype1 == multiplechoice %'
Я пытаюсь получить конкретный экземпляр из поля 'questiontype1' в модели Survey, часть которого выглядит следующим образом
from django.db import models
from datetime import datetime
# Create your models here.
class Survey(models.Model):
category = models.CharField(max_length=100, blank = True)
description = models.CharField(max_length=5000, blank = True)
location = models.CharField(max_length=10000, blank = True)
image = models.ImageField (upload_to='images/')
created_at = models.DateTimeField(default=datetime.now, blank = True)
question1 = models.CharField(max_length=10000, blank = True)
questiontype1 = models.CharField(max_length=100, blank = True)
bol1 = models.BooleanField()
choice1a = models.CharField(max_length=5000, blank = True)
choice2a = models.CharField(max_length=5000, blank = True)
choice3a = models.CharField(max_length=5000, blank = True)
choice4a = models.CharField(max_length=5000, blank = True)
question2 = models.CharField(max_length=10000, blank = True)
questiontype2 = models.CharField(max_length=100, blank = True)
Вот часть шаблона представления, которая связана с рассматриваемой моделью
<div class="mb-3 mx-5">
<label for="question1" class="form-label ">Question 1</label>
<input type="text" name="question1" class="form-control form-control-lg" id="question1" placeholder="question1">
<div class="mb-4 mx-5">
<label for="questiontype1" class="form-label">Question type</label>
<div class="col-md-6">
<select name="questiontype1" id="questiontype" class="form-select col-md-6">
<option value="null">Select question type</option>
<option value="multiplechoice">Multiple choice</option>
<option value="freetext">Free text</option>
<option value="trueorfalse">True or False</option>
</select>
</div>
</div>
Итак, в файле survey.html я хочу проверить условие 'questiontype1' и вывести следующий раздел
{% extends 'base.html' %}
{% block 'survey'%}
<form action = "" enctype="multipart/form-data" method="POST">
<div class="mt-10 mx-5 p-5">
<h1 class="mx-5 mt-3"> Answer Survey</h1>
{% csrf_token %}
<div class="mb-4 mx-5">
<label for="choices1" class="form-label">{{survey.question1}}</label>
{{% if survey.questiontype1 == multiplechoice %}}
<div class="col-md-6">
<select name="choices1" id="choices1" class="form-select col-md-6">
<option value="choice1a">{{survey.choice1a}}</option>
<option value="choice2a">{{survey.choice2a}}</option>
<option value="choice3a">{{survey.choice3a}}</option>
<option value="choice4a">{{survey.choice4a}}</option>
</select>
</div>
{{% elseif survey.questiontype1 == trueorfalse %}}
<div class="input-group mb-3">
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" name= "bol1" value="bol1" aria-label="Checkbox for following text input">
</div>
<input type="text" class="form-control" aria-label="Text input with checkbox">
</div>
{{% else %}}
<div class="mb-3 mx-5">
<label for="answer1" class="form-label ">Enter text</label>
<input type="text" name="answer1" class="form-control form-control-lg" id="answer1" placeholder="answer1">
</div>
{{% endif %}}
</div>
Однако я получаю следующую ошибку: Could not parse the remainder: '% if survey.questiontype1 == multiplechoice %' from '% if survey.questiontype1 == multiplechoice %'. Вот моя функция представления
def survey(request, pk):
survey = Survey.objects.get(id=pk)
return render(request, 'survey.html', {'survey':survey, 'survey':survey})
В чем может быть проблема?