本文整理汇总了Python中rest_framework.response.Response.content方法的典型用法代码示例。如果您正苦于以下问题:Python Response.content方法的具体用法?Python Response.content怎么用?Python Response.content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.response.Response
的用法示例。
在下文中一共展示了Response.content方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import content [as 别名]
def delete(self, request, obj_id, format=None):
try:
obj = self.queryset.objects.get(appcivist_id=obj_id)
obj.delete()
content = JSONRenderer().render({'text': 'The object was deleted correctly'})
resp = Response(status=status.HTTP_200_OK)
resp.content = content
return resp
except Exception as e:
resp = Response(status=status.HTTP_400_BAD_REQUEST)
resp.content = e
return resp
示例2: get
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import content [as 别名]
def get(self, request, obj_id, format=None):
try:
api = get_api_obj(self.initiative)
obj_raw = getattr(api, self.api_method)(**self.api_method_params)
obj = self.create_obj(obj_raw.id, self.initiative, obj_raw)
serializer = self.serializer_class(obj)
return Response(serializer.data)
except IdeaScalyError as e:
resp = Response(status=status.HTTP_400_BAD_REQUEST)
resp.content = 'Error: {}'.format(e.reason)
return resp
except Exception as e:
resp = Response(status=status.HTTP_400_BAD_REQUEST)
resp.content = e
return resp
示例3: post
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import content [as 别名]
def post(self, request, assembly, format=None):
respmsg = "inicio"
try:
api = get_api_obj(assembly)
api.ignore_admin_user = "true"
api.social_ideation_source = request.data['source'] # indicates the name of the providerId (e.g., social_ideation_facebook)
api.social_ideation_source_url = request.data['source_url'] # source to the original post
api.social_ideation_user_source_url = request.data['user_url'] # link to the user
api.social_ideation_user_source_id = request.data['user_external_id'] # email or id of the user in the source social network
api.social_ideation_user_name = request.data['user_name'] # the name of the author in the social network
api.assembly_id = assembly.appcivist_id
new_obj_raw = getattr(api, self.api_method)(**self.api_method_params)
new_obj_id = find_obj_id(new_obj_raw)
new_obj= self.create_obj(new_obj_id, assembly, new_obj_raw)
serializer = self.serializer_class(new_obj)
if self.filters:
new_obj.sync = True
new_obj.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
except Exception as e:
resp = Response(status=status.HTTP_400_BAD_REQUEST)
resp.content = e
return resp
示例4: post
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import content [as 别名]
def post(self, request, initiative, format=None):
try:
api = get_api_obj(initiative)
new_obj_raw = getattr(api, self.api_method)(**self.api_method_params)
new_obj= self.create_obj(new_obj_raw.id, initiative, new_obj_raw)
serializer = self.serializer_class(new_obj)
if self.filters:
new_obj.sync = True
new_obj.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
except IdeaScalyError as e:
resp = Response(status=status.HTTP_400_BAD_REQUEST)
resp.content = 'Error: {}'.format(e.reason)
return resp
except Exception as e:
resp = Response(status=status.HTTP_400_BAD_REQUEST)
resp.content = e
return resp
示例5: get
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import content [as 别名]
def get(self, request, format=None):
try:
assemblies = Assembly.objects.all()
serializer = AssemblySerializer(assemblies, many=True)
return Response(serializer.data)
except Exception as e:
resp = Response(status=status.HTTP_400_BAD_REQUEST)
resp.content = e
return resp
示例6: get_bitstream_data
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import content [as 别名]
def get_bitstream_data(request,id):
"""
Return data from an especified bitstream.
"""
try:
bitstream_data = Bitstream.retrieve(dspace,id,**dict(request.query_params))
response = Response(status=status.HTTP_200_OK)
response.content = bitstream_data
return response
except Collection.DoesNotExist:
raise Http404