DEV Community

Ivan López
Ivan López

Posted on • Edited on

Hidden keys on django projects

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..

Top comments (0)