django ImportError: cannot import name list_route

余生颓废 提交于 2021-01-01 02:32:08

问题


Im trying to add a new endpoint by marking it with @list_route but when i try to import if :

from rest_framework.decorators import list_route

It cant find it. Do i need to install something for this to work (I'm new to django)?


回答1:


The list_route decorator is present in version 3.1.3. See: https://github.com/tomchristie/django-rest-framework/blob/3.1.3/rest_framework/decorators.py

Follow the instructions on https://github.com/tomchristie/django-rest-framework to install Django REST Framework properly.

To install version 3.1.3, run: pip install djangorestframework==3.1.3




回答2:


When upgrading to higher versions, you might hit this question again. list_route has been deprecated in favor of @action(detail=False)

More info in the release 3.8 announcement



来源:https://stackoverflow.com/questions/31490341/django-importerror-cannot-import-name-list-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!