title: How can I do a redirect from the backend Django
body: <p>I have an application served with React Js for the frontend and Django for the backend. Upon sending some informations to the server, I would like to make a redirect that would occur on the frontend, is it possible ? If so how ?
  I tried redirecting but it didn't work</p>
  <p>The front-end (reactJs)</p>
  <pre><code>async function PaymentHandler(e) {
      e.preventDefault();
   
      const data = { command_id: order._id, price: order.TotalPrice };
  
      try {
       
        const res = await axios.post(&quot;/api/orders/Details/&quot;, data);
      } catch (error) {
        console.log(&quot;THERES AN ERROR : &quot;, error);
      }
    }
    return loading ? (
      &lt;Loader /&gt;
    ) : error ? (
      &lt;Message variant=&quot;danger&quot;&gt;{error}&lt;/Message&gt;
    ) : (
      &lt;div&gt;
        
          &lt;Button
          variant=&quot;outline-primary&quot;
          className=&quot;mt-3&quot;
          onClick={PaymentHandler}
          &gt;
              PAY NOW
          &lt;/Button&gt;
      &lt;/div&gt;
      )
  </code></pre>
  <p>Model.py</p>
  <pre><code>class Stuff(models.Model):
      paymentDetails = models.JSONField()
  </code></pre>
  <p>Model serializer</p>
  <pre><code>class PaymentSerializer(serializers.ModelSerializer):
  paymentDetails = serializers.JSONField()
  class Meta:
      model = Stuff
      fields = '__all__'
  </code></pre>
  <p>views.py</p>
  <pre><code>from rest_framework.decorators import api_view
  from django.shortcuts import redirect
  from base.models import Stuff
  from base.serializers import PaymentSerializer
  import requests
  import json
  
  
  @api_view(['POST'])
  def getPaymentDetails(request):
      data = request.data
      payment = Stuff.objects.create(
          paymentDetails = data
      )
      serializer = PaymentSerializer(payment, many=False)
      last = Stuff.objects.last()
     
      details = (last.paymentDetails)
      print('cmd id value :', details['command_id'])
      print('price id value :', details['price'])
  
      headers = {&quot;Content-Type&quot;: &quot;application/json&quot;,&quot;Authorization&quot;: &quot;Bearer eyJ0exxxxxxxxxxxx&quot;}
      url = &quot;https://apps.somewebsite.com/&quot;
      payload = {&quot;payment_data&quot;:{
          &quot;command_id&quot;:details['command_id'],
          &quot;price&quot;:details['price']},
          &quot;data&quot;:{&quot;return_url&quot;:&quot;some return url&quot;,
          &quot;cancel_url&quot;:&quot;some cancel url&quot;,
          &quot;shop_code&quot;:1}}
      r = requests.post(url, headers=headers, json=payload)
      print('request result : ', r.text)
      result = r.text
      result=json.loads(result)
   
      if result['status'] == 1:
          print ('payment token = ', result['payment_token'])
          
          return redirect('https://welcome.somewebsite.com/payment/'+result['payment_token'])
  </code></pre>