DjangoRestFramework类序列化器缺少“Meta”属性?

前端之家收集整理的这篇文章主要介绍了DjangoRestFramework类序列化器缺少“Meta”属性?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在 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)

怎么解决

解决方法

Meta不等于Meta. Python区分大小写.
原文链接:https://www.f2er.com/html5/240999.html

猜你在找的HTML5相关文章