I'm trying to GET fetch my REST API in DRF, but keep getting the error below. What could be the problem? Thanks!
Internal Server Error: /polls/
.....
.....
TypeError: 'type' object is not iterable
[08/Aug/2021 07:02:50] "GET /polls/ HTTP/1.1" 500 100344
Not Found: /favicon.ico
[08/Aug/2021 07:02:53] "GET /favicon.ico HTTP/1.1" 404 3415
The apiviews code: apiviews.py
class PollList(generics.ListCreateAPIView):
queryset = Poll.objects.all()
serializer_class = PollSerializer
The polls code: models.py
class Poll(models.Model):
question = models.CharField(max_length=100)
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
pub_date = models.DateTimeField(auto_now=True)
Serializer.py:
class PollSerializer(serializers.ModelSerializer):
choices = ChoiceSerializer(many=True, read_only=True, required=False)
class Meta:
model = Poll
fields = '__all__'
urls.py:
urlpatterns = [
path("polls/", PollList.as_view(), name="polls_list"),
]
Admin URLs:
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^', include('vote.urls')),
]
Here's portions of the traceback:
Internal Server Error: /polls/
Traceback (most recent call last):
File "D:\Studio\Python\REST\elections\env\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
....
....
\rest_framework\views.py", line 400, in initial
self.check_permissions(request)
File "D:\Studio\Python\REST\elections\env\lib\site-packages\rest_framework\views.py", line 332, in check_permissions
for permission in self.get_permissions():
File "D:\Studio\Python\REST\elections\env\lib\site-packages\rest_framework\views.py", line 279, in get_permissions return [permission() for permission in self.permission_classes]
TypeError: 'type' object is not iterable
Here's the Settings.py code implementing the Authentication:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication'
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated'
)
}
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
....
....
]