【发布时间】:2020-03-22 16:22:28
【问题描述】:
我在我的 django react 项目中添加了 JWT 身份验证。我想要实现的是我想在没有身份验证的情况下公开一些 api。它是一个电子商务项目,我想公开类别列表 API,以便任何人无需身份验证即可访问。
settings.py:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES':[
#'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
#'rest_framework.authentication.SessionAuthentication',
# 'rest_framework.authentication.TokenAuthentication',
],
'DEFAULT_PERMISSION_CLASSES':[
'rest_framework.permissions.IsAuthenticated',
#'rest_framework.permissions.AllowAny',
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE':10,
}
views.py:
@permission_classes((IsAuthenticated,))
class UserViewSet(viewsets.ModelViewSet):
queryset = CustomUser.objects.all()
serializer_class = serializers.UserSerializer
#User Registration View
class CreateUserView(generics.CreateAPIView):
model = get_user_model()
permission_classes = [
permissions.AllowAny
]
serializer_class = serializers.RegisterSerializer
#Category Listing View
@permission_classes((IsAuthenticated,))
class CategoryView(generics.ListCreateAPIView):
queryset = Category.objects.all()
serializer_class = CategorySerializers
class CategoryDetailView(generics.RetrieveUpdateAPIView):
queryset = Category.objects.all()
serializer_class = CategorySerializers
还想从类别列表中删除分页
【问题讨论】:
标签: django django-rest-framework