我正在尝试为现有(有点旧)的django项目添加REST支持。按照这里的指示http://www.django-rest-framework.org/tutorial/quickstart/我添加了一行
from rest_framework import routers
到文件urls.py
。但后来我得到了这个错误:
File "/Users/paolini/piprints/cvgmt/urls.py" in <module>
8. from rest_framework import routers
File "/Users/paolini/.virtualenvs/cvgmt/lib/python2.7/site-packages/rest_framework/routers.py" in <module>
24. from rest_framework import views
File "/Users/paolini/.virtualenvs/cvgmt/lib/python2.7/site-packages/rest_framework/views.py" in <module>
21. from rest_framework.response import Response
File "/Users/paolini/.virtualenvs/cvgmt/lib/python2.7/site-packages/rest_framework/response.py" in <module>
13. from rest_framework.serializers import Serializer
File "/Users/paolini/.virtualenvs/cvgmt/lib/python2.7/site-packages/rest_framework/serializers.py" in <module>
1534. ModelSerializer.serializer_field_mapping[postgres_fields.JSONField] = JSONField
Exception Type: AttributeError at /
Exception Value: 'module' object has no attribute 'JSONField'
不知道如何处理这个问题。错误似乎在库中,而不是我的代码。
djangorestframework == 3.7.1 Django的== 1.8.8
答案 0 :(得分:1)
自版本3.7以来,对django 1.8的支持已被删除。无论是更新您的django版本还是降级restframework,无论哪种方式最适合您。
更多信息here