Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
Redirecting a user to checkout page in Django

I want to redirect a user to checkout page that is automatically generated by the payment gateway. Anytime a user submits a request, the payment gateway returns a response in the format below. What i want to do is redirect the user to the checkout page to make payment.

 "status": true,
  "message": "Authorization URL created",
  "data": {
    "authorization_url": "https://checkout.paystack.com/eddno1f6rf411p0",
    "access_code": "eddno1f6rf411p0",
    "reference": "bpozkels2v"

def paystack(request):
    url = 'https://api.paystack.co/transaction/initialize'
    transaction_id = random.randint(100000000000, 999999999999)
    data = {
            "key": "PUBLIC_KEY",
            "ref": transaction_id,
            "amount": "000000000100",
            "callback": f"http://127.0.0.1:8000",
            "email": "email@me.com",
        }
    headers =  {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer SECRET_KEY',
        'Cache-Control': 'no-cache'
    }
    res = requests.post(url, data=json.dumps(data), headers=headers)
    response_data = res.json()
    print(response_data["authorization_url"])
    redirect(response_data["authorization_url"])

The error i get is

 KeyError at /paystack
'authorization_url'

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

GIven the response is as in the question text, you first should access the subdictionary for the "data" key, so:

response_data['data']['authorization_url']
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda