我对 DFR 很菜鸟,所以我正在按照教程进行学习。 到目前为止一切都很好,但在最后一部分,here ,我必须向 API 添加架构,并且按照说明进行操作,因此安装 coreapi 并添加
from rest_framework.schemas import get_schema_view
schema_view = get_schema_view(title='Pastebin API')
urlpatterns = [
path('schema/', schema_view),
...
]
在tutorial/urls.py中,所以我完整的tutorial/urls.py是:
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from rest_framework.schemas import get_schema_view
schema_view = get_schema_view(title='Pastebin API')
urlpatterns = [
url(r'^admin/', admin.site.urls),
path('', include('snippets.urls')),
path('api-auth/', include('rest_framework.urls')),
path('schema/', schema_view),
]
但是如果我从浏览器访问/schema/http://127.0.0.1:8000/schema/ ,我得到:
AttributeError at /schema/
'Request' object has no attribute 'accepted_renderer'
由于我按照教程的说明进行操作,所以我不明白如何修复此错误。
我的配置是:
coreapi 2.3.3
coreschema 0.0.4
Django 2.1.3
djangorestframework 3.9.0
最佳答案
有两种解决方案:
安装 pyyaml:
pip install pyyaml
或
恢复 DRF:
pip install djangorestframework==3.8.0
关于rest - Django REST Framework 与accepted_renderer 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53561706/