django-rest-framework-tutorial icon indicating copy to clipboard operation
django-rest-framework-tutorial copied to clipboard

/musics/views.py中的detail函数

Open CrisJk opened this issue 6 years ago • 6 comments

新的框架中取消了from rest_framework.decorators import detail_route, list_route ,改成了from rest_framework.decorators import action .

@detail_route(methods=['get']) def detail(self, request, pk=None):

这句会报TypeError, bool object is not callable错误

解决办法是更改函数名detail

我在运行这个tutorial的时候花了近30分钟的时间才找到这个错误,希望后面学习的人可以避免这个问题

CrisJk avatar May 09 '18 13:05 CrisJk

@CrisJk requirements.txt 中有指定 django<2.0, 如果你是安裝 django 2.0 ,的確會遇到類似的問題, 但還是謝謝提醒。(本教學是依照 django<2.0 所寫的,有機會我再來寫 django 2.0 的教學 )

twtrubiks avatar May 10 '18 06:05 twtrubiks

@twtrubiks 确实是我没有仔细看requirements.txt,谢谢你的辛苦创作

CrisJk avatar May 10 '18 08:05 CrisJk

新的框架中取消了from rest_framework.decorators import detail_route, list_route ,改成了from rest_framework.decorators import action .

@detail_route(methods=['get']) def detail(self, request, pk=None):

这句会报TypeError, bool object is not callable错误

解决办法是更改函数名detail

我在运行这个tutorial的时候花了近30分钟的时间才找到这个错误,希望后面学习的人可以避免这个问题

谢谢分享

hjf-codecrazy avatar Apr 21 '19 15:04 hjf-codecrazy

碰到一模一樣的問題,還好有找到這裡,感謝分享

chien0515 avatar Aug 02 '19 09:08 chien0515

新的框架中取消了from rest_framework.decorators import detail_route, list_route ,改成了from rest_framework.decorators import action .

@detail_route(methods=['get']) def detail(self, request, pk=None):

这句会报TypeError, bool object is not callable错误

解决办法是更改函数名detail

我在运行这个tutorial的时候花了近30分钟的时间才找到这个错误,希望后面学习的人可以避免这个问题

我也遇到这个问题了,困扰了一天,解决办法确实是改个名字,头大~~~

BigYoungs avatar Dec 26 '19 03:12 BigYoungs

可以參考 branch , 我之後有補充上去了 https://github.com/twtrubiks/django-rest-framework-tutorial/tree/django2#extra-actions-for-routing

twtrubiks avatar Dec 31 '19 07:12 twtrubiks