我想在django app中使用DjangoRestframework,但是在调用它时会出错?
打电话给我时,我会回复我:
Exception Type: AssertionError
Exception Value: Class CrawlerSerializers missing "Meta" attribute
但是我在serializer
类
请帮帮我
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)
如何解决?
答案 0 :(得分:9)
meta
不等于Meta
。 Python区分大小写。
答案 1 :(得分:0)
用元
替换元 class Meta: #instead of meta write Meta (Capital M)
model = Crawler
fields = ('source','category','template','url')