【发布时间】:2021-02-13 21:07:19
【问题描述】:
我正在尝试使用以下APIview 函数查询模型以检查对象是否存在。不幸的是,我无法在 react native apisauce get 函数中接收任何响应对象,如下所示
apisauce函数
const checkIfUserExists = (email) =>
client.get("/account/user-exists/?email=" + email);
APIView 类
class UserExistsView(APIView):
"""Checks if user exists or not"""
def get(self, request, *args, **kwargs):
username = self.request.GET['email']
try:
user = models.UserProfile.objects.get(email=username)
except models.UserProfile.DoesNotExist:
return Response(data={'message': False})
else:
return Response(data={'message': True})
在shell<Response status_code=200, "text/html; charset=utf-8">上打印结果
【问题讨论】:
-
你能告诉你在浏览器中究竟得到了什么。另外,您为什么要在列表中返回该数据?有什么具体要求吗?
-
我在问题中添加了更多信息。我添加列表只是为了测试。我已删除
-
DRF 视图似乎没有任何问题。您还可以提供整个 checkIfUserExists 功能吗?我在这里没有看到任何 .then()。
标签: reactjs react-native django-rest-framework