Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Charlie Thomas
Charlie Thomas
40,856 Points

Django - setup credentials and objects for API

I want to intergrate several APIs into my django app. I would like to intergrate Sendgrid for emails and Braintree for payments. Both of these require me to either create an object or call a setup function.

I don't want to put this code in a view function because it would be inefficient. So where should I put it? Also, these APIs require private credentials so where should I store them, as I want to share my projects publically on Github etc.

If its any help I have linked to the docs below:

1 Answer

Kenneth Crocken
Kenneth Crocken
10,672 Points

Hey Charlie ...

I wouldn't have a problem with putting the code in the views.py. In Django, the view is more akin to a controller.

As for the API keys, for local development I would split up the settings.py file, placing anything with sensitive information in a separate file and just require that file in the settings.py.

Here is a good discussion of this.