django - Returning custom message when a permission is denied in DRF -


django rest framework has an excellent piece of documentation permissions. i've been able use pre-made permission classes , built own.

however, there api methods in "permission denied" generic message not informative user. example, if user authenticated account has expired, nice let user know account expired , not permission denied error.

when building custom permission classes, either return true or false - according documentation. like, said above, show more informative message user. how accomplish this?

since drf 3.2.0, have add message attribute :

from rest_framework import permissions  class customeraccesspermission(permissions.basepermission):     message = 'adding customers not allowed.'      def has_permission(self, request, view):  

see drf documentation: http://www.django-rest-framework.org/api-guide/permissions/#custom-permissions


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -