Hello guys,
I am struggling to determine what seems to be the issue here. There error
that I get is: NameError: name 'viewsets' is not defined
I am following the Quick Start Tutorial while using Python3 and Django 2.1
Here is my views.py code:
from django.shortcuts import render
from django.contrib.auth.models import User, Group
from rest_framework import viewsets
from . serializers import UserSerializer, GroupSerializer
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
serializer_class = UserSerializer
queryset = User.objects.all().order_by('-date_joined')
class GroupViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
serializer_class = GroupSerializer
queryset = Group.objects.all()
And here is my urls.py code:
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
from rest_framework import routers
from quickstart import views
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'
))
]
As you can see, I have imported the viewsets and declared them for the
class argument. Please let me know what am I doing wrong. Here is the link
for the short
tutorial: https://www.django-rest-framework.org/tutorial/quickstart/
Thank you!!
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.