我的模特是:
class Skill(models.Model):
skill = models.CharField()
我的观点:
class SkillViewset(viewsets.ModelViewSet):
queryset = Skill.objects.all()
serializer_class = SkillSerializer
filter_backends = (filters.SearchFilter, filters.OrderingFilter )
search_fields = ('id', 'skill')
ordering_fields = '__all__'
def get_queryset(self):
queryset = property_models.Skill.objects.all()
skill = self.request.query_params.get('skill', None)
if skill is not None:
queryset = queryset.filter(skill__icontains=skill)
return queryset
我的一种语言是" C ++"
这有效:
Skill.objects.filter(skill__icontains='C++')
然而,调用我的api不起作用:
/skills/?skill=c++
答案 0 :(得分:3)
这是因为您必须对参数进行网址编码,以便c++
成为c%2B%2B
https://www.w3schools.com/tags/ref_urlencode.asp