2016-03-31 107 views
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) 

在此先感谢。

回答

3

你应该使用ListCreateAPIViewListCreateAPIVIEW

替换此:

class AnimalList(generics.ListCreateAPIVIEW): 

有了这个:

class AnimalList(generics.ListCreateAPIView): 

django-rest-framework docs

相关问题