我正在尝试按照以下链接中的教程开始使用Django REST Framework: 的 http://www.django-rest-framework.org/tutorial/quickstart/
但是,按照此处的说明,我在启动服务器后遇到如下错误:
Could not import 'rest_framework.renderers.JSONRenderer' for API setting 'DEFAULT_RENDERER_CLASSES'. ImportError: cannot import name serializers.
它在某种程度上感觉像是兼容性问题所以我查找了我的软件包版本并提出了以下内容:
我想知道是否有人可能对这个问题有什么想法。抱歉,如果我没有提供足够的信息,很乐意提供更多信息,只是不确定此时的相关内容。
谢谢!
- 更新
感谢Kevin,添加以下链接命令的输出:
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]:
答案 0 :(得分:3)
pip install djangorestframework --upgrade