我正在尝试创建一个API视图,但我收到一个错误.有人可以帮忙吗?
urls.py:
app_name = 'ads'
urlpatterns = [
# ex: /ads/
url(r'^$', views.ListBrand.as_view(), name='brand_list'),
]
Run Code Online (Sandbox Code Playgroud)
views.py:
from rest_framework.views import APIView
from rest_framework.response import Response
from . import models
from . import serializers
class ListBrand(APIView):
def get(self, request, format=None):
brands = models.Brand.objects.all()
serializer = serializers.BrandSerializer(brands, many=True)
data = serializer.data
return Response(data)
Run Code Online (Sandbox Code Playgroud)
更新:这里是错误,这是一个字符串错误.我似乎无法找到它的来源.
TypeError at /api/v1/ads/
'str' object is not callable
Request Method: GET
Request URL: http://localhost/api/v1/ads/
Django Version: 1.10.2
Exception Type: TypeError
Exception Value:
'str' object is not callable
Exception Location: …Run Code Online (Sandbox Code Playgroud)