I'm following this tutorial, trying to make an API for my Products
table.
Here's my .views/API/apitest.py view:
from my_app.views.API.serializers import ProductSerializer
from my_app.models import Product
from rest_framework import generics
class APITest(generics.ListAPIView):
model=Product
serializer_class=ProductSerializer
queryset = Product.objects.all()
The urls.py entry:
url(r'^API/products/$', views.API.apitest.as_view(), name='apitest')
That line gives an error: 'module' object has no attribute 'as_view'
. I'm just trying to create a simple example for the moment, so there's no need for decorators. What causes this error? I'm using Django 1.9.2.
apitest is the module, you need to use as_view
on the class
url(r'^API/products/$', views.API.apitest.APITest.as_view(), name='apitest')
Although it may be better to look into your imports
from myapp.views.API.apitest import APITest
url(r'^API/products/$', APITest.as_view(), name='apitest')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With