TypeError at /matriculas/
APIView.dispatch() missing 1 required positional argument: 'request'
Request Method: GET
Request URL: http://127.0.0.1:8000/matriculas/
Django Version: 4.1
Exception Type: TypeError
Exception Value:
APIView.dispatch() missing 1 required positional argument: 'request'
Exception Location: C:\Users\Francisco Otacilio\eclipse-workspace\drf-escola-projeto_inicial-master\escola\views.py, line 40, in dispatch
Raised during: escola.views.MatriculaViewSet
Python Executable: C:\Users\Francisco Otacilio\eclipse-workspace\drf-escola-projeto_inicial-master\venv\Scripts\python.exe
Python Version: 3.10.4
Python Path:
['C:\\Users\\Francisco '
'Otacilio\\eclipse-workspace\\drf-escola-projeto_inicial-master',
'C:\\Users\\Francisco '
'Otacilio\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
'C:\\Users\\Francisco '
'Otacilio\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
'C:\\Users\\Francisco '
'Otacilio\\AppData\\Local\\Programs\\Python\\Python310\\lib',
'C:\\Users\\Francisco Otacilio\\AppData\\Local\\Programs\\Python\\Python310',
'C:\\Users\\Francisco '
'Otacilio\\eclipse-workspace\\drf-escola-projeto_inicial-master\\venv',
'C:\\Users\\Francisco '
'Otacilio\\eclipse-workspace\\drf-escola-projeto_inicial-master\\venv\\lib\\site-packages']
Server time: Tue, 30 Aug 2022 21:43:56 -0300
esse é o código
from rest_framework import viewsets, generics
from rest_framework import status
from escola.models import Aluno, Curso, Matricula
from escola.serializer import AlunoSerializer, AlunoSerializerV2, CursoSerializer, MatriculaSerializer, ListaMatriculasAlunoSerializer, ListaAlunosMatriculadosSerializer
from rest_framework.response import Response
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
class AlunosViewSet(viewsets.ModelViewSet):
"""Exibindo todos os alunos e alunas"""
queryset = Aluno.objects.all()
def get_serializer_class(self):
if self.request.version == 'v2':
return AlunoSerializerV2
else:
return AlunoSerializer
class CursosViewSet(viewsets.ModelViewSet):
"""Exibindo todos os cursos"""
queryset = Curso.objects.all()
serializer_class = CursoSerializer
def create(self, request):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
serializer.save()
response = Response(serializer.data, status=status.HTTP_201_CREATED)
id = str(serializer.data['id'])
response['Location'] = request.build_absolute_uri() + id
return response
class MatriculaViewSet(viewsets.ModelViewSet):
"""Listando todas as matrículas"""
queryset = Matricula.objects.all()
serializer_class = MatriculaSerializer
http_method_names = ['get', 'post', 'put', 'path']
@method_decorator(cache_page(40))
def dispatch(self, request, *args, **kwargs):
return super(MatriculaViewSet, self).dispatch(*args, **kwargs)
class ListaMatriculasAluno(generics.ListAPIView):
"""Listando as matrículas de um aluno ou aluna"""
def get_queryset(self):
queryset = Matricula.objects.filter(aluno_id=self.kwargs['pk'])
return queryset
serializer_class = ListaMatriculasAlunoSerializer
class ListaAlunosMatriculados(generics.ListAPIView):
"""Listando alunos e alunas matriculados em um curso"""
def get_queryset(self):
queryset = Matricula.objects.filter(curso_id=self.kwargs['pk'])
return queryset
serializer_class = ListaAlunosMatriculadosSerializer