0
我正在使用'Django Rest Framework',我正在嘗試構建一個RestfulAPI。但是,當我嘗試「makemigrations」即同步數據庫時,出現上述錯誤。AttributeError:'模塊'對象沒有屬性'ListCreateAPIVIEW'Django
這裏是我的模型:
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class Animal(models.Model):
id = models.CharField(max_length=10, primary_key=True)
name = models.CharField(max_length=200)
gender = models.CharField(max_length=10)
breed = models.CharField(max_length=200)
adoption = models.CharField(max_length=10)
vaccines = models.CharField(max_length=20)
class Doctor(models.Model):
id= models.CharField(max_length=10, primary_key=True)
name = models.CharField(max_length=20)
這是我的觀點:
from django.contrib.auth.models import User, Group
from rest_framework import viewsets, generics
from cw.myStart.models import Animal
from cw.myStart.serializers import UserSerializer, GroupSerializer, AnimalSerialiser, DoctorSerealiser
from models import Animal, Doctor
class AnimalList(generics.ListCreateAPIVIEW):
queryset = Animal.objects.all()
serializer_class = AnimalSerialiser
class DoctorDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Doctor.objects.all()
serializer_class = DoctorSerealiser
這裏是我的urls.py:
from django.conf.urls import url, include
from rest_framework import routers
from rest_framework.urlpatterns import format_suffix_patterns
from cw.myStart 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')),
url(r'^api/$', views.AnimalList.as_view()),
url(r'^api/(?P<pk>[0-9]+)/$', views.AnimalDetail.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
在此先感謝。