我想在
django app中使用DjangoRestframework,但是在调用它时会出错?
打电话给我,我回复我:
Exception Type: AssertionError Exception Value: Class CrawlerSerializers missing "Meta" attribute
但我在序列化器类中编写了Meta Class
请帮我
serializers.py文件:
from rest_framework import serializers from models import * class CrawlerSerializers(serializers.ModelSerializer): class Meta: model = Crawler fields = ('source','category','template','url')
我的View.py文件:
from rest_framework import status from rest_framework.decorators import api_view from rest_framework.response import Response from models import * from serializers import * # Create your views here. @api_view(['GET','POST']) def crawler_list(request): ''' list all task,or create a new task. ''' if request.method == 'GET': crawler = Crawler.objects.all() serializer = CrawlerSerializers(crawler) return Response(serializer.data) elif request.method == "POST": serializer = CrawlerSerializers(data=request.Data) if serializer.is_valid(): serializer.save() return Response(serializer.data,status=status.HTTP_201_CREATED) else: return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
怎么解决?