Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DjangoRestFramework Class Serializers missing "Meta" attribute?

I want to use DjangoRestframework in django app but i get error when call it?

When call it , i give response me :

Exception Type: AssertionError
Exception Value: Class CrawlerSerializers missing "Meta" attribute

But i written Meta Class in serializer class

Please help me

serializers.py file :

from rest_framework import serializers
from models import *

class CrawlerSerializers(serializers.ModelSerializer):
    class meta:
        model = Crawler
        fields = ('source','category','template','url')

my View.py file :

 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)

How to solve it?

like image 916
Saeed Gharedaghi Avatar asked Jun 08 '15 14:06

Saeed Gharedaghi


1 Answers

meta does not equal Meta. Python is case-sensitive.

like image 90
Daniel Roseman Avatar answered Sep 22 '22 18:09

Daniel Roseman