1
router.register('search', views.SearchCourseViewSet, 'search') # 搜索课程
1234567891011121314
from rest_framework.viewsets import GenericViewSetfrom rest_framework.mixins import ListModelMixinfrom rest_framework.filters import SearchFilterfrom . import models, serializers# 搜索课程接口classSearchCourseViewSet(GenericViewSet, ListModelMixin): queryset = models.Course.objects.filter(is_delete=False, is_show=True).all() serializer_class = serializers.CourseSerializer pagination_class = pagination.PageNumberPagination filter_backends = [SearchFilter] search_fields = ['name']