Why getting .accepted_renderer not set on Response error in django?

I want to return response to my react Js frontend here is my code

def save_stripe_info(request):
    email = 'testing@gmail.com'
    payment_method_id = 'pm_1K5xfXBbWBJ638dR1WMitwx1'
    # creating customer
    customer = stripe.Customer.create(
      email=email, payment_method=payment_method_id)
     
    return Response(status=status.HTTP_200_OK, 
      data={
        'message': 'Success', 
        'data': {'customer_id': customer.id} 
      }  
    )        

but getting error

AssertionError: .accepted_renderer not set on Response

How can I resolve this. I saw this How to resolve AssertionError: .accepted_renderer not set on Response in django and ajax but this is for only django and returning an HTML page as a template

How can I solve this error

in your views.py file from rest_framework.decorators import api_view and then before the defination of function write @api_view(['POST'])

@api_view(['POST'])
def save_stripe_info(request):
    email = 'testing@gmail.com'
    payment_method_id = 'pm_1K5xfXBbWBJ638dR1WMitwx1'
    # creating customer
    customer = stripe.Customer.create(
      email=email, payment_method=payment_method_id)
     
    return Response(status=status.HTTP_200_OK, 
      data={
        'message': 'Success', 
        'data': {'customer_id': customer.id} 
      }  
    )     

hope this will solve your problem!

Back to Top