title: Why am I getting AttributeError: 'QuerySet' object has no attribute
body: <p>I was testing Django http output.</p>
  <p>In the Django shell, the output is normal, but when an http request is sent, AttributeError: 'QuerySet' object has no attribute.</p>
  <p>models.py</p>
  <pre><code>from django.db import models
  from django.db.models.deletion import CASCADE
  
  # Create your models here.
  
  class Actor(models.Model):
      first_name = models.CharField(max_length=45)
      last_name = models.CharField(max_length=45)
      date_of_birth = models.DateField(auto_now=False, null=True)
      movies = models.ManyToManyField('Movie', through='Actor_Movie')
      class Meta:
          db_table=&quot;actors&quot;
  
  
  class Movie(models.Model):
      title = models.CharField(max_length=45)
      release_date = models.DateField(auto_now=False, null=True)
      running_time = models.TimeField(auto_now=False, null=True)
      class Meta:
          db_table=&quot;movies&quot;
  
  class Actor_Movie(models.Model):
      actors = models.ForeignKey('Actor', on_delete=models.CASCADE)
      movies = models.ForeignKey('Movie', on_delete=models.CASCADE)
  </code></pre>
  <p>urls.py</p>
  <pre><code>from django.urls import path, include
  from .views import *
  
  urlpatterns = [
          path('',MoviesView.as_view()),
          ]
  </code></pre>
  <p>views.py</p>
  <pre><code>from django.http import request
  from django.http.response import JsonResponse
  from django.shortcuts import render
  from django.views import View
  from .models import Actor, Movie, Actor_Movie
  import json
  
  # Create your views here.
  
  class MoviesView(View):
      def get(self,request):
          ac = Actor.objects.all()
          results=[]
          for a in ac:
              c =[i for i in ac.movies.values(&quot;title&quot;)]
              results.append(
                  {
                      &quot;first_name&quot; : a.first_name,
                      &quot;movies&quot; : c,
                  }
              )
          return JsonResponse({&quot;result&quot;:results}, status = 201)
  </code></pre>
  <p>server request command</p>
  <pre><code>http -v GET 127.0.0.1:8000/movies
  </code></pre>
  <p>output screen</p>
  <pre><code>WARNINGS:
  ?: (urls.W002) Your URL pattern '/dogs' has a route beginning with a '/'. Remove this slash as it is unnecessary. If this pattern is targeted in an include(), ensure the include() pattern has a trailing '/'.
  
  System check identified 1 issue (0 silenced).
  November 16, 2021 - 14:55:33
  Django version 3.2.9, using settings 'dogs.settings'
  Starting development server at http://127.0.0.1:8000/
  Quit the server with CONTROL-C.
  Internal Server Error: /movies
  Traceback (most recent call last):
    File &quot;/Users/jinsungpark/miniconda3/envs/dogs/lib/python3.9/site-packages/django/core/handlers/exception.py&quot;, line 47, in inner
      response = get_response(request)
    File &quot;/Users/jinsungpark/miniconda3/envs/dogs/lib/python3.9/site-packages/django/core/handlers/base.py&quot;, line 181, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File &quot;/Users/jinsungpark/miniconda3/envs/dogs/lib/python3.9/site-packages/django/views/generic/base.py&quot;, line 70, in view
      return self.dispatch(request, *args, **kwargs)
    File &quot;/Users/jinsungpark/miniconda3/envs/dogs/lib/python3.9/site-packages/django/views/generic/base.py&quot;, line 98, in dispatch
      return handler(request, *args, **kwargs)
    File &quot;/Users/jinsungpark/wecode/dogs/movies/views.py&quot;, line 15, in get
      c =[i for i in ac.movies.values(&quot;title&quot;)]
  AttributeError: 'QuerySet' object has no attribute 'movies'
  [16/Nov/2021 14:55:36] &quot;GET /movies HTTP/1.1&quot; 500 69966
  </code></pre>
  <p>I want to print some movies and actors, it works fine in the shell.</p>
  <pre><code>In [81]: b = Movie.objects.get(id=1)
  
  In [82]: b.actor_set.values(&quot;last_name&quot;)
  Out[82]: &lt;QuerySet [{'last_name': '정우'}]&gt;
  
  In [83]: a.movies.values(&quot;title&quot;)
  Out[83]: &lt;QuerySet [{'title': '암살'}, {'title': '신과 함께'}]&gt;
  
  In [84]: e = a.movies.values(&quot;title&quot;)
  
  In [85]: [i for i in e]
  Out[85]: [{'title': '암살'}, {'title': '신과 함께'}]
  
  In [86]: [i for i in e]
  Out[86]: [{'title': '암살'}, {'title': '신과 함께'}]
  
  In [87]: e = a.movies.values_list(&quot;title&quot;)
  
  In [88]: [i for i in e]
  Out[88]: [('암살',), ('신과 함께',)]
  
  In [89]: c= [i for i in e]
  
  In [90]: c
  Out[90]: [('암살',), ('신과 함께',)]
  
  In [91]:
  </code></pre>