我有一个ViewSet:
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
合适的网址:
from .users.api.views import UserViewSet
router = routers.DefaultRouter()
router.register('users', UserViewSet, 'user')
urlpatterns = [
url(r'^v1/', include(router.urls)),
]
它有效,但我想在UserViewSet中添加用户名密码验证:
@list_route(methods=['post'], permission_classes=[AllowAny])
def login(self, request):
#check login and password
#creare and return token
对于cource,我可以自己编写它,但我很感兴趣,我如何使用rest_framework.authtoken.views.ObtainAuthToken
来实现我的目标。