title: AttributeError: 'NoneType' object has no attribute 'get' - How to solve it when I even have the data and no field is None?
body: <p>I am creating a Django app. I will write the short summary of the system how it is supposed to work and then I will share my code.</p>
  
  <p>When user (student) will go to the <code>performance_calculator.html</code> he/she will see a textbox where he/she will have to enter the relevant subject name. After entering the subject name, he/she will click 'Calculate' button, on the other side (server-side) the entered name will be taken and the system will search the detail (progress) of that subject of that user (student) from the Detail Model using the subject name and that user name as filters. After getting the the progress detail, each value in the detail will be assigned to a separate single variable. Those variables will be passed as parameters to <code>fuzz_algo()</code> function (a Fuzzy Logic Algorithm to calculator Performance), after getting the result, result will be forward to Client Side (Front End) using Django Messages Module.</p>
  
  <p>This was the summary, now I get the error at the step when the system tries to get the progress details of the subject (whose name was entered by user) of the user (student who is using the system). and the Error is <code>AttributeError: 'NoneType' object has no attribute 'get'</code>. I know this error happens when we receive <code>None</code> from somewhere and we try to get something from <code>None</code>. But I have populated the Detail Model along with the Subject Model using the Admin Panel (screenshots are attached). I don't know why I am getting <code>None</code> and due to <code>None</code>, this <code>AttributeError</code>. </p>
  
  <p>My views.py</p>
  
  <pre><code>def performanceCalculator(request):
      skype = 0
      internal_course = 0
      prg_lab = 0
      mid_marks = 0
      final_marks = 0
      sub = 0
      if request.method == 'POST':
          performance_form = PerformanceCalculatorForm(request.POST)
  
          if performance_form.is_valid():
              performance_form.save()
  
              sub = performance_form.cleaned_data.get('subject')
              skype = Detail.objects.filter(subject__subject=sub, user__username=User.username).values().first().get('skype_session_attendance')
              internal_course = Detail.objects.filter(subject__subject=sub, user__username=User.username).values().first().get('internal_course_marks')
              prg_lab = Detail.objects.filter(subject__subject=sub, user__username=User.username).values().first().get('programming_lab_activity')
              mid_marks = Detail.objects.filter(subject__subject=sub, user__username=User.username).values().first().get('mid_term_marks')
              final_marks = Detail.objects.filter(subject__subject=sub, user__username=User.username).values().first().get('final_term_marks')
  
              result = fuzz_algo(skype, internal_course, prg_lab, mid_marks, final_marks)
  
              messages.success(request, result)
  
              return redirect('performance_calculator')
      else:
          performance_form = PerformanceCalculatorForm()
  
      context = {
          'performance_form': performance_form
      }
  
      return render(request, 'users/performance_calculator.html', context)
  </code></pre>
  
  <p>My models.py</p>
  
  <pre><code>class Subject(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      subject = models.CharField(max_length=100)
  
      def __str__(self):
          return '{} ({})'.format(self.subject, self.user.username)
  
  
  class Detail(models.Model):
      user = models.ForeignKey(User, on_delete=models.CASCADE)
      subject = models.OneToOneField(Subject, on_delete=models.CASCADE)
      skype_session_attendance = models.FloatField()
      internal_course_marks = models.FloatField()
      programming_lab_activity = models.FloatField()
      mid_term_marks = models.FloatField()
      final_term_marks = models.FloatField()
  
      def __str__(self):
          return f'{self.subject, (self.user.username)} Details'
  
  class Sub(models.Model):
      s = models.CharField(max_length=100
  </code></pre>
  
  <p>My forms.py</p>
  
  <pre><code>class PerformanceCalculatorForm(forms.ModelForm):
      subject = forms.CharField(max_length=100)
  
      class Meta:
          model = Sub
          fields = ['subject']
  </code></pre>
  
  <p>My template (users/performance_calculator.html)</p>
  
  <pre><code>{% if not request.user.is_superuser and not request.user.is_staff %}
                          &lt;div class="account-heading"&gt;
                              &lt;h2&gt;
                                  Performance Calculator
                              &lt;/h2&gt;
                          &lt;/div&gt;
  
                          &lt;div class="content-section"&gt;
                              &lt;form method="POST"&gt;
                                  {% csrf_token %}
                                  &lt;fieldset class="form-group"&gt;
                                      &lt;legend class="border-bottom mb-4"&gt;&lt;/legend&gt;
                                      {{ performance_form|crispy }}
                                  &lt;/fieldset&gt;
                                  &lt;div class="from-group"&gt;
                                      &lt;button class="btn btn-outline-info" type="submit"&gt;Calculate&lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/form&gt;
                          &lt;/div&gt;
                      {% endif %}
  </code></pre>
  
  <p>This is the full error that I get:</p>
  
  <pre class="lang-none prettyprint-override"><code>AttributeError at /esacp/performance-calculator/
  'NoneType' object has no attribute 'get'
  Request Method: POST
  Request URL:    http://localhost:8000/esacp/performance-calculator/
  Django Version: 3.0.3
  Exception Type: AttributeError
  Exception Value:    
  'NoneType' object has no attribute 'get'
  Exception Location: C:\Users\khubi\OneDrive\Desktop\FYP\test_phase\users\views.py in performanceCalculator, line 61
  Python Executable:  C:\environments\bsse_fyp\Scripts\python.exe
  Python Version: 3.8.1
  Python Path:    
  ['C:\\Users\\khubi\\OneDrive\\Desktop\\FYP\\test_phase',
   'C:\\Users\\khubi\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
   'C:\\Users\\khubi\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
   'C:\\Users\\khubi\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
   'C:\\Users\\khubi\\AppData\\Local\\Programs\\Python\\Python38-32',
   'C:\\environments\\bsse_fyp',
   'C:\\environments\\bsse_fyp\\lib\\site-packages']
  Server time:    Thu, 14 May 2020 11:55:41 +0000
  </code></pre>
  
  <p>Now, below are the screenshots of Admin Panel showing the populated Subject and Detail model:
  This is the main Django Admin Panel, see the actions at the right side?
  <a href="https://i.stack.imgur.com/FC2qB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FC2qB.png" alt="enter image description here"></a></p>
  
  <p>This is the Subject Model, see 4 subjects are added, 2 of one student and 2 of other.
  <a href="https://i.stack.imgur.com/vpher.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vpher.png" alt="enter image description here"></a></p>
  
  <p>This is the Detail Model of one Subject of the user (student). See the details are entered and fields are not <code>None</code> or empty
  <a href="https://i.stack.imgur.com/pIWAG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pIWAG.png" alt="enter image description here"></a></p>
  
  <p>Now I don't understand, why am I getting the error where there is nothing empty.</p>
  
  <p>P.S. Yes, I logged in with the same user (student) whose subject detail is populated in the screenshot above. If you see in Template, I have <code>if condition</code> at start that if the user is not staff and not superuser, only then that form will be shown. So it's obvious with the Django Admin Panel logged in, i won't see that Performance Calculator form, I will only see the form if I am logged in with the regular account. But I am still getting the error.</p>