twtrubiks / django-rest-framework-tutorial

Django-REST-framework 基本教學 - 從無到有 DRF-Beginners-Guide 📝
MIT License
845 stars 179 forks source link

/musics/views.py中的detail函数 #3

Open CrisJk opened 6 years ago

CrisJk commented 6 years ago

新的框架中取消了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分钟的时间才找到这个错误,希望后面学习的人可以避免这个问题

twtrubiks commented 6 years ago

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

CrisJk commented 6 years ago

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

hjf-codecrazy commented 5 years ago

新的框架中取消了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分钟的时间才找到这个错误,希望后面学习的人可以避免这个问题

谢谢分享

chien0515 commented 5 years ago

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

BigYoungs commented 4 years ago

新的框架中取消了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分钟的时间才找到这个错误,希望后面学习的人可以避免这个问题

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

twtrubiks commented 4 years ago

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