我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用rest_framework.parsers.FormParser()。
def post(self, request, *kwargs): parser = FormParser() query_dict = parser.parse(request) contact = Contact.objects.filter(number=query_dict["From"]).first() if not contact: contact = Contact(number=query_dict["From"]) contact.save() if contact.number != os.environ["TWILIO_NUMBER"]: sender = "them" else: sender = "you" text = Text(sender=sender, contact=contact, body=query_dict["Body"]) text.save() return HttpResponse()
def select_parser(self, request, parsers): if request.method == 'POST': parsers = [FormParser(), MultiPartParser()] return super(ConditionalContentNegotiation, self).select_parser( request, parsers )