slee slee - 1 year ago 153
Python Question

Serializer Import Error on Django Rest Framework

I am attempting to get started with the Django REST Framework by following the tutorial at the following link:

However, in following the directions here I'm running into an error once I start my server that goes as follows:

Could not import 'rest_framework.renderers.JSONRenderer' for API setting 'DEFAULT_RENDERER_CLASSES'. ImportError: cannot import name serializers.

It somehow feels like a compatibility issue so I looked up my package versions and came up with the following:

  • Django==1.7.7

  • djangorestframework==3.1.1

  • Python==2.7.6

I was wondering if anyone might have any ideas on what the issue might be. Apologies if I didn't provide enough information, happy to provide more, just not sure exactly what's relevant at this point.



Thanks Kevin, adding the output from the command you linked below:

In [1]: from rest_framework.renderers import JSONRenderer
ImportError Traceback (most recent call last)
<ipython-input-1-92bc65a288f2> in <module>()
----> 1 from rest_framework.renderers import JSONRenderer

C:\Anaconda64\lib\site-packages\rest_framework\ in <module>()
18 from django.test.client import encode_multipart
19 from django.utils import six
---> 20 from rest_framework import exceptions, serializers, status, VERSION
22 from rest_framework.exceptions import ParseError

C:\Anaconda64\lib\site-packages\rest_framework\ in <module>()
40 # serializer fields more explicit.
---> 42 from rest_framework.relations import * # NOQA
43 from rest_framework.fields import * # NOQA

C:\Anaconda64\lib\site-packages\rest_framework\ in <module>()
9 from django.utils.translation import ugettext_lazy as _
10 from rest_framework.compat import OrderedDict
---> 11 from rest_framework.fields import get_attribute, empty, Field
12 from rest_framework.reverse import reverse
13 from rest_framework.utils import html

C:\Anaconda64\lib\site-packages\rest_framework\ in <module>()
----> 1 from rest_framework import serializers
3 from .models import User, Post, Photo

ImportError: cannot import name serializers

In [2]:

Answer Source

I had the same problem, for me upgrade the django rest solved the problem! I used this command

pip install djangorestframework --upgrade
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download