问题
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