slee slee - 11 days ago 7
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:
http://www.django-rest-framework.org/tutorial/quickstart/

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!

-- UPDATE

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\renderers.py 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
21 from rest_framework.compat import SHORT_SEPARATORS, LONG_SEPARATORS, INDENT_SEPARATORS
22 from rest_framework.exceptions import ParseError

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

C:\Anaconda64\lib\site-packages\rest_framework\relations.py 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\fields.py in <module>()
----> 1 from rest_framework import serializers
2
3 from .models import User, Post, Photo
4
5

ImportError: cannot import name serializers

In [2]:

Answer

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

pip install djangorestframework --upgrade
Comments