cannot import name detail_route错误
文章目錄
在看Django-rest-framework2时,看到Tutorial 6: ViewSets & Routers,执行from rest_framework.decorators import detail_route
时,报cannot import name detail_route错误
查看decorators.py源码,发现原因是从2.4.0才有这个方法,而公司用的是2.3.14,所以没有。
在view里添加detail_route的代码1
2
3
4
5
6
7
8
9
10def detail_route(methods=['get'], **kwargs):
"""
Used to mark a method on a ViewSet that should be routed for detail requests.
"""
def decorator(func):
func.bind_to_methods = methods
func.detail = True
func.kwargs = kwargs
return func
return decorator