Custom Configurations in Django - 22

What we're going to want to do is be able to establish the key we have from PayPal and create them using a custom configuration. Nothing could be easier.

mystore\mystore\settings.py

PAYPAL_CLIENT_ID = '<YOURCLIENTID>'
PAYPAL_SECRET =  '<YOURSECRETID>'
PAYPAL_BASE_URL = 'https://api-m.sandbox.paypal.com' #'https://api-m.paypal.com'

The above configurations are the PayPal public/client and secret keys, which you must obtain from the PayPal developer portal presented above.

We also configure the base URL for development:

'https://api-m.sandbox.paypal.com'

And this would be the one we use in production, that is, to make real payments:

'https://api-m.paypal.com'

And references from the view:

mystore\elements\views.py

from django.conf import settings
***
def detail(request, pk):

   element = Element.objects.get(id=pk)
   return render(request,'elements/detail.html',
                 {'element': element, 'paypal_client_id': 
                  settings.PAYPAL_CLIENT_ID})

I agree to receive announcements of interest about this Blog.

Let's learn how to create our own configurations.

- Andrés Cruz

En español

This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y Libro desarrollo web con Django 5 y Python 3 + integración con Vue 3, Bootstrap y Alpine.js.

) )