2016-03-31 19 views
0

私は 'Django Rest Framework'を使用していますが、RestfulAPIを構築しようとしています。しかし、私は 'makemigrations'、つまりDBを同期しようとすると上記のエラーが発生します。AttributeError: 'module'オブジェクトに '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

あなたはこの置き換えListCreateAPIViewないListCreateAPIVIEW

を使用することになっている:django-rest-framework docs

を参照してください

class AnimalList(generics.ListCreateAPIView): 

:これにより

class AnimalList(generics.ListCreateAPIVIEW): 

関連する問題