【发布时间】:2018-12-12 11:33:54
【问题描述】:
如何在 django 项目中测试以下函数?
@api_view(['GET'])
def get_films(request):
if request.method == "GET":
r = requests.get('https://swapi.co/api/films')
if r.status_code == 200:
data = r.json()
return Response(data, status=status.HTTP_200_OK)
else:
return Response({"error": "Request failed"}, status=r.status_code)
else:
return Response({"error": "Method not allowed"}, status=status.HTTP_400_BAD_REQUEST)
【问题讨论】:
标签: django testing django-rest-framework