我最近在接受采访时被问到这个问题.我在mySQL中尝试了这个,得到了相同的结果(最终结果).All给出了该特定表中的行数.任何人都可以解释它们之间的主要区别.
我使用django-rest-framework创建了RESTFul API.用户端点是
/api/v1/users
Run Code Online (Sandbox Code Playgroud)
我想创建新用户.我以JSOn格式发送用户数据.
{
"username": "Test1",
"email": "test1@gmail.com",
"first_name": "Test1",
"last_name": "Test2",
"password":"12121212"
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Chrome扩展程序Postman来测试api.但用户数据尚未保存.回应是:
{
"detail": "Unsupported media type \"text/plain;charset=UTF-8\" in request."
}
Run Code Online (Sandbox Code Playgroud)
附上截图

我需要发送一个pdf文件和一些其他参数来响应使用django rest框架的get API调用.
我该怎么做?我尝试了这个,但它给出了一个错误<django.http.HttpResponse object at 0x7f7d32ffafd0> is not JSON serializable.
@detail_route(methods=['get'])
def fetch_report(self, request, *args, **kwargs):
short_report = open("somePdfFile", 'rb')
response = HttpResponse(FileWrapper(short_report), content_type='application/pdf')
return Response({'detail': 'this works',
'report': response})
Run Code Online (Sandbox Code Playgroud)