title: How to check whether the value of radio button selected is right or wrong from Django models?
body: <p>I'm making a quiz app in Django. It is a MCQ type of quiz app where users have to select the answer from a list of multiple answers.</p>
  
  <p><a href="https://i.stack.imgur.com/9aora.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9aora.png" alt="This is how my Quiz app looks for better understanding the question."></a> </p>
  
  <p>Now, in my models.py there are three models:</p>
  
  <ol>
  <li>Quiz</li>
  <li>Question</li>
  <li>Answer</li>
  </ol>
  
  <p>Where Quiz model defines the type of quiz (For example Basic, Intermediate, Advance), Question model has a ForeignKey of Quiz to specify the type of question and a CharField to mention the text of the question. The Answer model is similar to Question model but with ForeignKey of Question to specify the question that answer is related to, CharField for the text of the answer and a BooleanField to specify if that answer is correct or not.</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  
  # Create your models here.
  
  class Quiz(models.Model):
      q_name = models.CharField(max_length=30)
      desc = models.CharField(max_length=100)
  
      def __str__(self):
          return self.q_name
  
  class Question(models.Model):
      quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE)
      label = models.CharField(max_length=1000)
  
      def __str__(self):
          return self.label
  
  class Answer(models.Model):
      question = models.ForeignKey(Question, on_delete=models.CASCADE)
      text = models.CharField(max_length=1000)
      is_correct = models.BooleanField(default=False)
  
      def __str__(self):
          return self.text
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wnO8N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wnO8N.png" alt="This is how my Answer model looks in the admin page"></a></p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from django.shortcuts import render, redirect, reverse
  from django.contrib import messages
  from .models import Quiz, Question, Answer
  
  def basic_quest(request, quiz_name, ques_no):
      if request.method == "POST":
          guess = request.POST.get('answer')
          ans = Answer.objects.get(text = guess)
          if ans.is_correct == True:
              messages.success(request,("Correct"))
              return redirect('basic_quest')
          else:
              messages.error(request,("Wrong"))
      else:
          question = Question.objects.get(id = ques_no)
          answers = Answer.objects.filter(question = ques_no)
          return render(request, 'quest.html', {'question' : question, 'answers' : answers})
  </code></pre>
  
  <p><strong>quest.html</strong></p>
  
  <pre><code>{% extends 'base.html' %}
  
  {% block title %}
      Question - Quiz Python
  {% endblock title %}
  
  {% block content %}
      &lt;div class="container"&gt;
          {% if messages %}
              {% for message in messages %}
                  &lt;div class="alert alert-primary alert-dismissible fade show" role="alert"&gt;
                      {{ message }}
                      &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;
                          &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
              {% endfor %}
          {% endif %}
  
          &lt;p&gt;&lt;h1&gt;{{ question.label }}&lt;/h1&gt;&lt;/p&gt;
          &lt;form method="POST"&gt;
              {% csrf_token %}
              {% for answer in answers %}
              &lt;label&gt;&lt;input type="radio" name="answer" value={{ answer.text }}&gt; {{ answer.text }}&lt;/label&gt;
              &lt;/br&gt;
              {% endfor %}
              &lt;input type="submit"&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  {% endblock content %}
  </code></pre>
  
  <p>After selecting the answer using the radio button and clicking on submit I want it to display a message on the same page as correct or incorrect by checking the value of the radio button selected with the answer available in the Answer model.</p>
  
  <p>But I'm getting the following error:</p>
  
  <pre><code>NoReverseMatch at /quiz/Basic/1
  Reverse for 'basic_quest' with no arguments not found. 1 pattern(s) tried: ['quiz/(?P&lt;quiz_name&gt;[^/]+)/(?P&lt;ques_no&gt;[^/]+)$']
  Request Method: POST
  Request URL:    http://localhost:8000/quiz/Basic/1
  Django Version: 2.2.7
  Exception Type: NoReverseMatch
  Exception Value:    
  Reverse for 'basic_quest' with no arguments not found. 1 pattern(s) tried: ['quiz/(?P&lt;quiz_name&gt;[^/]+)/(?P&lt;ques_no&gt;[^/]+)$']
  Exception Location: /Users/apple/Desktop/myvenv/quiz/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 673
  Python Executable:  /Users/apple/Desktop/myvenv/quiz/bin/python
  Python Version: 3.7.4
  Python Path:    
  ['/Users/apple/Desktop/quiz',
   '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
   '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
   '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
   '/Users/apple/Desktop/myvenv/quiz/lib/python3.7/site-packages']
  </code></pre>