I'm new in Django and Rest Framework and I didn't find how to do that:
Filter an endpoint request without argument to return Bad Request. Example:
get_foo/?foo_id=
Return:
{
"status": 400,
"error": "Bad Request"
}
At this time, a get request without argument gives all the values from the database. It's a big DB, so I have to do this filter.
CodePudding user response:
You could filter it so If you have an empty queryset you will get that response:
If foo_id == '' # or If not foo_id
return Response(
{"res": "Bad Request"},
status=status.HTTP_404_NOT_FOUND)
else:
return . . .
In your resposne you can also put your text
If foo_id == '' # or If not foo_id
return Response({
"status": 400,
"error": "Bad Request"})