while working with serializers in Django Shell I had to import from basics.serializers import ArticleSerializer the error I'm getting is :
P.S. I'm a beginner at the rest framework of Django
ImportError Traceback (most recent call last) in ----> 1 from basics.serializers import ArticleSerializer
ImportError: cannot import name 'ArticleSerializer' from 'basics.serializers' (C:\Users\Sony\PycharmProjects\pythonProject\Frameworks of python\django\django_rest_framework\basics\serializers.py)
basics\serializer.py the code for the serializer.py is:
from rest_framework import serializer
from basics.models import Article
class ArticleSerializer(serializers.Serializer):
title = serializers.CharField(max_length=100)
author = serializers.CharField(max_length=100)
email = serializers.EmailField(max_length=300)
date = serializers.DateField()
def create(self, validated_data):
return Article.objects.create(validated_data)
def update(self, instance, validated_data):
instance.title = validated_data.get('title', instance.title)
instance.author = validated_data.get('author', instance.author)
instance.email = validated_data.get('email', instance.email)
instance.date = validated_data.get('date', instance.date)
instance.save()
return instance
I call it in the terminal using python manage.py shell as:
In [4]: from basics.serializers import ArticleSerializer
can someone please guide me what should be done
CodePudding user response:
it should be from basics.serializer import ArticleSerializer not basics.serializers. Is it a spelling mistake?