I'm not sure how to implement a redirect to login if the user is doesn't meet the permissions criteria, as the documentation states: "Before running the main body of the view each permission in the list is checked." - so overriding methods in the view is fruitless. If anyone could point me in the right direction? Thanks!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Django Rest Framework is a toolkit to build web APIs. It doesn't render pages filled with content - it just serializes and sends the information which you requested. And in case you don't have the permission to access a resource on server, DRF sends you either a 401 Unauthorized
status, or a 403 Forbidden
status responses.
In order to redirect a user to the login page, you should do this in the frontend, after receiving a 401
status, which means that the user is not authenticated.