3

I am trying to serialize model instance as i can't reach out the url or the details of the 'followiing' model.

from django.core import serializers
from django.contrib.auth import authenticate
from django.contrib.auth.models import update_last_login
from rest_framework_jwt.settings import api_settings
from django.core import serializers
from rest_framework import serializers
from urllib import request
from rest_framework.permissions import AllowAny,IsAuthenticated
from rest_framework import routers, serializers, viewsets
from django.http import HttpResponse



class UserSerializer(serializers.HyperlinkedModelSerializer):
    jsonfollowing = serializers.serialize('json', [ followiing ,])

    class Meta:
        model = User
        fields  = ('id','email','username','password','followiing','jsonfollowing')

But i get the following error

AttributeError: module 'rest_framework.serializers' has no attribute 'serialize'

Does anybody know why?

1 Answer 1

3

I believe you are trying to serialize from django.core, but you are overriding the django.core import with rest_framework, so use of as should do the job:

from django.core import serializers as core_serializers
from django.contrib.auth import authenticate
from django.contrib.auth.models import update_last_login
from rest_framework_jwt.settings import api_settings
from django.core import serializers
from rest_framework import serializers
from urllib import request
from rest_framework.permissions import AllowAny,IsAuthenticated
from rest_framework import routers, serializers, viewsets
from django.http import HttpResponse

class UserSerializer(serializers.HyperlinkedModelSerializer):
    jsonfollowing = core_serializers.serialize('json', [ followiing ,])

    class Meta:
        model = User
        fields  = ('id','email','username','password','followiing','jsonfollowing')
Sign up to request clarification or add additional context in comments.

4 Comments

now i get this error NameError: name 'followiing' is not defined
I think it should be following not followiing
ìn models it is defined as followiing(i had some unknown clashes with some other models etc.. so i had to define it like that),so there is no typing error.It gives me same error when i try other models.
anyways,the main issue is solved so i am closing this case.Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.