DEV Community

loading...

Hidden keys on django projects

Ivan López
backend developer, I like to take pictures in my free time and I like to share what I'm learning.
Updated on ・1 min read

One best practices in software development is hide ours project keys, for example: database name, password database, etc.

To carry out this practice in our projects with Django we can use the following package: Python Decouple .

First activate the project virtual enviroment:

source env/bin/activate

Install python-decouple

pip install python-decouple
Enter fullscreen mode Exit fullscreen mode

Create the .env file inside folder project:

.env file location

Inside file .env, write the password , path to key .json, etc... data sensible of settings project file.

this is an example:

.env example

And your settings file import your enviroment variables:

from decouple import config
Enter fullscreen mode Exit fullscreen mode

Use variables inside your file:

python decouple use

Ready, your data sensible is hidden.

Note: The enviroment variables could use in any file.

Important: Not Upload .env file to repository

see you..

Discussion (0)